1
I’m setting up a simple search engine for a paper bank at a student science event. Adapting codes of some guides I found on the internet the system is working all right. The only problem is that it only returns results with exact words.
For example: If I want to return an article that talks about Information Organization and search for "Information Organization", the system returns nothing. The user needs to put in the search exactly "Organization of Information".
I found a topic here in Stack that seems to me to contain the solution of the problem in the answers, however I could not apply in my system. Follow the link: Search with LIKE or MATCH.. AGAINST in two columns
I ask you to analyze my code and help me, if possible, in how to fit the tips in my system or if you have a better way of doing, please give me a light.
Follow the PHP code I’m using for the search (I removed only the pagination codes from the results):
<?php
// A busca
$busca = $_GET['consulta'];
$busca = mysql_real_escape_string($busca);
$sql = "SELECT * FROM `artigos` WHERE (`ativa` = 1) AND ((`titulo` LIKE '%".$busca."%') OR (`resumo` LIKE '%".$busca."%') OR ('%".$busca."%')) ORDER BY `grupo` DESC LIMIT ".$inicio.", ".$_BS['PorPagina'];
// Executa a consulta
$query = mysql_query($sql);
// Mostra resultados
echo "<ul>";
while ($resultado = mysql_fetch_assoc($query)) {
$titulo = $resultado['titulo'];
$resumo = $resultado['resumo'];
$link = 'http://meusite.com.br/artigos/' . $resultado['link'];
echo "<li>";
echo '<a href="'.$link.'" title="'.$titulo.'">'.$titulo.'</a><br />';
echo "<p>";
echo '<p>'.$resumo.'</p>';
echo "</li>";
}
echo "</ul>";
?>
Thanks for your help.
Hugs!
Exactly here is the solution: http://answall.com/a/13181/7210 where you’re having trouble.
– Jorge B.
Jorge, I just mentioned this link in my doubt. The problem is that it didn’t work. I used it as follows: I replaced the string "$search = 'green car smashed ';" with "$search = $search".
– Marcos Falcão
This link is the same for your problem, when you implemented came to give some result?
– Skywalker
I tried to exchange AND for OR, but nothing. It just keeps returning the exact terms. If any word is between them, the search returns nothing.
– Marcos Falcão