[英]mysql keyword search fulltext
I am looking for a keyword search on my website and having a bit of difficulties 我正在我的网站上寻找关键字搜索,遇到了一些麻烦
$q = "SELECT * from post WHERE post_k like '%".$_GET['s']."%'";
website url after search is website.com/?s=keyword 搜索后的网站网址是website.com/?s=keyword
I am not getting fulltext searches. 我没有全文搜索。 For example if I search for robin I can get results from batman because they both have n in the word. 例如,如果我搜索“知更鸟”,我可以从蝙蝠侠那里得到结果,因为它们的单词中都含有n。 I am looking for a search that if I type robin I will only get results from robin. 我正在寻找一个搜索,如果我键入robin,我只会从robin中得到结果。
Thanks 谢谢
You need to use MATCH AGAINST
with FULLTEXT INDEX
. 您需要对FULLTEXT INDEX
使用MATCH AGAINST
。
CREATE FULLTEXT INDEX search_index ON post (post_k);
Then your query would be more like (Example using prepared statements with MySQLi): 然后您的查询将更像(示例与MySQLi一起使用预准备语句):
$query = $mysqli->prepare("SELECT * FROM post WHERE MATCH(post_k) AGAINST(?)");
$query->bind_param('s', $_GET['s']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.