Torna indietro   AlterVista | Spazio web gratis, hosting free php mysql > Guide per il buon uso di AlterVista > How-To

Discussione chiusa
 
LinkBack Strumenti discussione Modalità visualizzazione
  #1 (permalink)  
Vecchio 08-03-2007, 16.29.54
Neofita
 
Data registrazione: 03-03-2007
Messaggi: 1
Thumbs up Drupal: soluzione problema modulo ricerca – “CREATE TEMPORARY TABLE”

Sistema trovato in internet che permette di aggirare il problema della creazione di tabelle temporanee.
Testato con successo su Drupal 5.1.
Per verificare: http://forum30013.altervista.org/?q=search/node

Due semplici passaggi:


1) Su phpMyAdmin eseguire la query

Citazione:
CREATE TABLE `temp_search_results` (
`type` varchar(16) default NULL,
`sid` int(10) unsigned NOT NULL default '0',
`score` double default NULL
) TYPE=MyISAM;
CREATE TABLE `temp_search_sids` (
`type` varchar(16) default NULL,
`sid` int(10) unsigned NOT NULL default '0',
`relevance` double default NULL,
`matches` bigint(21) NOT NULL default '0'
) TYPE=MyISAM;

2) In drupal\modules\search, nel file search.module sostituire, dopo avere fatto un backup del file, alla funzione do_search il seguente codice:

Codice PHP:
function do_search($keywords$type$join1 ''$where1 '1'$arguments1 = array(), $select2 'i.relevance AS score'$join2 ''$arguments2 = array(), $sort_parameters 'ORDER BY score DESC') {
$query search_parse_query($keywords);

if (
$query[2] == '') {
form_set_error('keys't('You must include at least one positive keyword with %count characters or more.', array('%count' => variable_get('minimum_word_size'3))));
}
if (
$query === NULL || $query[0] == '' || $query[2] == '') {
return array();
}

// First pass: select all possible matching sids, doing a simple index-based OR matching on the keywords.
// 'matches' is used to reject those items that cannot possibly match the query.
$conditions $where1 .' AND ('$query[2] .") AND i.type = '%s'";
$arguments array_merge($arguments1$query[3], array($type$query[4]));

//----G // Temporary table not allowed.

//$result = db_query_temporary("SELECT i.type, i.sid, SUM(i.score * t.count) AS relevance, COUNT(*) AS matches FROM {search_index} i INNER JOIN {search_total} t ON i.word = t.word $join1 WHERE $conditions GROUP BY i.type, i.sid HAVING COUNT(*) >= %d", $arguments, 'temp_search_sids');

$result db_query("CREATE TABLE IF NOT EXISTS temp_search_sids SELECT i.type, i.sid, SUM(i.score * t.count) AS relevance, COUNT(*) AS matches FROM {search_index} i INNER JOIN {search_total} t ON i.word = t.word $join1 WHERE $conditions GROUP BY i.type, i.sid HAVING COUNT(*) >= %d"$arguments);

// Calculate maximum relevance, to normalize it
$normalize db_result(db_query('SELECT MAX(relevance) FROM temp_search_sids'));
if (!
$normalize) {
return array();
}
$select2 str_replace('i.relevance''('. (1.0 $normalize) .' * i.relevance)'$select2);

// Second pass: only keep items that match the complicated keywords conditions (phrase search, negative keywords, ...)
$conditions '('$query[0] .')';
$arguments array_merge($arguments2$query[1]);
//----G // Temporary table not allowed.
//$result = db_query_temporary("SELECT i.type, i.sid, $select2 FROM temp_search_sids i INNER JOIN {search_dataset} d ON i.sid = d.sid AND i.type = d.type $join2 WHERE $conditions $sort_parameters", $arguments, 'temp_search_results');

$result db_query("CREATE TABLE IF NOT EXISTS temp_search_results SELECT i.type, i.sid, $select2 FROM temp_search_sids i INNER JOIN {search_dataset} d ON i.sid = d.sid AND i.type = d.type $join2 WHERE $conditions $sort_parameters"$arguments);

if ((
$count db_result(db_query('SELECT COUNT(*) FROM temp_search_results'))) == 0) {
return array();
}
$count_query "SELECT $count";

// Do actual search query
$result pager_query("SELECT * FROM temp_search_results"100$count_query);
$results = array();
while (
$item db_fetch_object($result)) {
$results[] = $item;
}
//----G // Temporary table not allowed.
db_query('DELETE LOW_PRIORITY FROM temp_search_sids');
db_query('DELETE LOW_PRIORITY FROM temp_search_results');
return 
$results;

Buon lavoro

30013
Discussione chiusa

Strumenti discussione
Modalità visualizzazione

Regole di scrittura
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Attivato
Le faccine sono Attivato
Il codice [IMG] è Attivato
Il codice HTML è Disattivato
Trackbacks are Attivato
Pingbacks are Attivato
Refbacks are Disattivato



Tutti gli orari sono GMT +1. Adesso sono le 07.31.05.