我有这个SQL查询:
SELECT DISTINCT url FROM paragraphs WHERE
MATCH (title) AGAINST('$query') ORDER BY
MATCH (title) AGAINST('$query') DESC
但是当我搜索“约翰史密斯”时,我会得到“约翰”,“约翰室”......等等。我怎样才能说出这两个字?
答案 0 :(得分:0)
您可以在过滤掉所有不需要的匹配项的位置添加额外的LIKE
子句:
SELECT DISTINCT url FROM paragraphs WHERE
MATCH (title) AGAINST('$query') AND title LIKE "%$query%"
ORDER BY MATCH (title) AGAINST('$query') DESC
因此,您有得分,只有结果完全匹配。
答案 1 :(得分:0)
在布尔搜索中使用+
应该包含所有单词:
<?php
$query = str_replace(" "," +",$query);
$sql = "SELECT DISTINCT url FROM paragraphs WHERE
MATCH (title) AGAINST('$query' IN BOOLEAN MODE))
ORDER BY score DESC;"
?>