[英]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. 我试图建立一个基于MySQL FULL TEXT的搜索引擎,但搜索没有任何结果。 I am working on MySQL Version is 5.5.24 which support FULL TEXT for Innodb.
我正在使用的MySQL版本是5.5.24,它支持Innodb的全文本。 so i have kept database type to Innodb for speed purpose, also my collation is utf8mb4_unicode_ci.
所以我出于速度目的将数据库类型保持为Innodb,我的排序规则也是utf8mb4_unicode_ci。
i have set field "title" type to TEXT and altered table "test_table" like. 我已经将字段“ title”类型设置为TEXT并更改了表“ test_table”。
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. 我尝试将数据库更改为MyISAM,但是存在相同的问题。
Please suggest what I am doing wrong here. 请在这里建议我做错了什么。
Thanks. 谢谢。
Try using the following: 尝试使用以下内容:
require_once('../global/includes/connect.php');
$db = mysql_select_db($database,$connection) or trigger_error("SQL", E_USER_ERROR);
$sqlquery = mysql_query("SELECT MATCH(title) FROM test_table WHERE MATCH(title) AGAINST ('security')") OR die(mysql_error());
while($row=mysql_fetch_assoc($sqlquery)){
echo $row['title'];
echo"</br>";
}
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. 希望这对其他人也有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.