【发布时间】:2016-04-04 16:54:24
【问题描述】:
我想在 MySQL 中编写一个布尔型全文搜索查询。但我想按这个顺序得到结果:
Exact Matches > Including all the words > Including some of the words
(> 表示更高。)
通过以下查询,我得到更高的完全匹配:
SELECT *, MATCH(name,description,address)
AGAINST('>("word1 word2 word3") <(word1 word2 word3)' IN BOOLEAN MODE)
AS score FROM samples WHERE MATCH(name,description,address)
AGAINST('>("word1 word2 word3") <(word1 word2 word3)' IN BOOLEAN MODE) ORDER BY score DESC
通过以下查询,我得到的文档包含的所有单词都高于包含查询的某些部分的单词:
SELECT *, MATCH(name,description,address)
AGAINST('>(+word1 +word2 +word3) <(word1 word2 word3)' IN BOOLEAN MODE)
AS score FROM samples WHERE MATCH(name,description,address)
AGAINST('>(+word1 +word2 +word3) <(word1 word2 word3)' IN BOOLEAN MODE) ORDER BY score DESC
但我想结合这两个查询。这是迄今为止我取得的最好成绩,但我没有得到我想要的结果。
SELECT *, MATCH(name,description,address)
AGAINST('>("word1 word2 word3") <(>(+word1 +word2 +word3) <(word1 word2 word3))' IN BOOLEAN MODE)
AS score FROM samples WHERE MATCH(name,description,address)
AGAINST('>("word1 word2 word3") <(>(+word1 +word2 +word3) <(word1 word2 word3))' IN BOOLEAN MODE)
ORDER BY score DESC
没有 UNION 有没有办法做到这一点?
【问题讨论】:
-
如果要匹配的单词超过 2 个,例如
match(..) against('>frist second third'),则无法执行此操作。您可能只需要使用union。
标签: mysql database full-text-search information-retrieval