如何使 myisam 表返回与不同单词组合匹配的结果,而不是给定搜索字符串的额外内容。
我在我的标签表上使用以下查询
SELECT * FROM tags WHERE MATCH (name) AGAINST('word1 word2'));
表格可能包含如下行
- 1个字1个字2个字3
- 2 word2 word3 word4
- 3个字1
- 4 word3 word2
- 5个字2
- 6 word2 word1
- 7 word1 word2
- 8 word3 word4
我只需要以下几行作为结果
- 3个字1
- 5个字2
- 6 word2 word1
- 7 word1 word2
但我得到的实际结果是
- 1个字1个字2个字3
- 2 word2 word3 word4
- 3个字1
- 4 word3 word2
- 5个字2
- 6 word2 word1
- 7 word1 word2
如何实现??
我已经尝试使用 +
进行 bool 模式搜索,但这使得给定 +
的单词在搜索结果中是强制性的,这不是我想要的。
最佳答案
这可能是一个迟到的回复,但是,这将解决问题。使用 MySQL FTS 的 IN BOOLEAN MODE
。
SELECT * FROM `tags` WHERE MATCH (`name`) AGAINST('+word1 +word2' IN BOOLEAN MODE)
Note In implementing this feature, MySQL uses what is sometimes referred to as implied Boolean logic, in which
+
stands for AND
-
stands for NOT
[no operator]
implies OR
关于mysql - mysql全文搜索中给定查询字符串的不同组合的精确单词匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13697513/