Search code examples
phpmysqlsearch-engine

MySQL Search Query Not Working


I am trying to build a MySQL FULL TEXT based search engine, i am not getting any results for search made. I am working on MySQL Version is 5.5.24 which support FULL TEXT for Innodb. so i have kept database type to Innodb for speed purpose, also my collation is utf8mb4_unicode_ci.

i have set field "title" type to TEXT and altered table "test_table" like.

ALTER TABLE `test_table` ADD FULLTEXT (`title`)

I am writing query like this but no result were displayed.

    require_once('../global/includes/connect.php');
$db = mysql_select_db($database,$connection) or trigger_error("SQL", E_USER_ERROR);

$sqlquery = mysql_query("SELECT title FROM test_table WHERE MATCH(title) AGAINST ('%keyword%')");
while($row=mysql_fetch_assoc($sqlquery)){
echo $row['title'];
echo"</br>";
}

for query like this

    $sqlquery = mysql_query("SELECT title FROM test_table ");
while($row=mysql_fetch_assoc($sqlquery)){
echo $row['title'];
echo"</br>";

results are displayed.

I tried changing database to MyISAM, but same problem.

Please suggest what I am doing wrong here.

Thanks.


Solution

  • got it, modified query

    $sqlquery = mysql_query("SELECT title FROM test_table WHERE MATCH (title) AGAINST ('keyword' IN BOOLEAN MODE) ")or die (mysql_error());
    

    Hope this helps others too.