Mysql全文搜索找不到一个字 - 为什么?

时间:2011-12-01 14:46:18

标签: mysql sql database full-text-search

(mysql 5.1.36)

我试图找出为什么当我在全文查询中搜索“三”这个词时,我得不到任何结果。如果单词“three”是字段中的唯一文本,或者它是句子的一部分,我会得到相同的结果。

很容易重现:

CREATE TABLE `test`( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT , `word` TEXT NOT NULL , PRIMARY KEY (`id`) ); 
ALTER TABLE `test` ADD FULLTEXT `NewIndex1` (`word`);
INSERT INTO `test`(`id`,`word`) VALUES ( NULL,'three');
INSERT INTO `test`(`id`,`word`) VALUES ( NULL,'thorn');

然后运行这些查询:

SELECT * FROM test WHERE word='three';

result = [1,'three']

SELECT word FROM test WHERE MATCH(word) AGAINST ('three*' IN BOOLEAN MODE );

result = []

SELECT word FROM test WHERE MATCH(word) AGAINST ('three' IN BOOLEAN MODE);

result = []

SELECT word FROM test WHERE MATCH(word) AGAINST ('thre*' IN BOOLEAN MODE );

result = []

SELECT word FROM test WHERE MATCH(word) AGAINST ('thorn*' IN BOOLEAN MODE )

result = [2,'thorn']

SELECT word FROM test WHERE MATCH(word) AGAINST ('thorn' IN BOOLEAN MODE)

result = [2,'thorn']

SELECT word FROM test WHERE MATCH(word) AGAINST ('thor*' IN BOOLEAN MODE)

result = [2,'thorn']

为什么全文搜索'three'不会返回任何结果?

2 个答案:

答案 0 :(得分:7)

因为三个是停用词,全文将忽略该单词并且不返回与单词“three”相关的结果。基本上,存在停用词以提高性能,并且不返回包含诸如“是,是,那里,有......”之类的单词的每一行。这是停留字的list,请检查它们。

答案 1 :(得分:2)

要添加上述答案:如果您确实要为全文索引添加停用词,只需将其添加到.cnf文件,重新启动MySQL引擎并重建索引: ft_stopword_file = ""除此之外,如果您还没有,请将最小单词降低到3(ft_min_word_len=3),以便能够搜索3个字母的单词。