Ho un motore di ricerca interno, che effettua la ricerca delle parole chiave immesse dall'utente in due diversi campi tabella del db (titolo e testo della news).
Questo è il codice:
Codice PHP:
$searchterm = $_POST["search"]; //ricevo l'input data
$searchterm = htmlspecialchars(addslashes($_POST["search"]));
$demo = new Highlighter();
@$rech = $searchterm;
$sentence = "";
if ($searchterm == "") {
echo "<p align=\"left\">Please, specify a criteria for search.</p>";
} else {
$result = mysql_query("SELECT *, MATCH(title,text) AGAINST('$searchterm' IN BOOLEAN MODE) AS tot FROM news WHERE MATCH(title,text) AGAINST ('$searchterm' IN BOOLEAN MODE) ORDER BY tot ASC");
$nr = mysql_num_rows($result);
if ($nr!==0) {
echo "[i]Result that match the news [keyword(s) highlighted].[/i]
";
while ($row = mysql_fetch_array($result)) {
$newsid = $row["news_id"];
$titolo = $row["title"];
$sentence .= "<a href=\"onefeed.php?feed=" . $newsid . "\">[b]" . $titolo . "[/b]</a>
";
}
if($demo->CheckSentence($sentence, $rech))
echo $demo->CheckSentence($sentence, $rech) ;
} else {
echo "[i]No result where the keyword(s) match the news.[/i]
";
}
}
Il problema è che, se viene inserita una sola parola come keyword di ricerca, tutto funziona perfettamente, ma se le parole sono due o più, non mi dà alcun risultato (anche se, invece, le parole sono presenti).
Se, ad es., faccio una ricerca con la keyword picasso, mi restituisce un'elenco tipo:
- PICASSO AT LOUVRE
- PABLO PICASSO MASTERPIECES
- THE ARTWORKS OF PABLO PICASSO
- BLUE AND PICASSO
mentre se le keywords sono due, pablo picasso, invece di darmi come risultato
- PABLO PICASSO MASTERPIECES
- THE ARTWORKS OF PABLO PICASSO
non mi da assolutamente nulla.
Dove #x!@+ è, l'errore?
Apprezzato qualsiasi help...