MySQL全文MATCH / AGAINST显示并不总是结果

时间:2017-11-02 18:03:25

标签: mysql full-text-search full-text-indexing

我有以下表格设置:

CREATE TABLE IF NOT EXISTS `search_table` (
  `fulltext_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity ID',
  `data_index` longtext COMMENT 'Data index',
  PRIMARY KEY (`fulltext_id`),
  FULLTEXT KEY `FTI_CATALOGSEARCH_FULLTEXT_DATA_INDEX` (`data_index`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='Search table' 
AUTO_INCREMENT=1;

INSERT INTO `search_table` (`fulltext_id`, `data_index`)
VALUES (1, 'Test Hello abc');

然后我尝试使用3种不同的查询文本进行全文搜索:

SELECT `s`.`fulltext_id`, MATCH (s.data_index) AGAINST ('Test' IN BOOLEAN MODE) AS `relevance` FROM `search_table` AS `s`
 WHERE (MATCH (s.data_index) AGAINST ('Test' IN BOOLEAN MODE));

SELECT `s`.`fulltext_id`, MATCH (s.data_index) AGAINST ('Hello' IN BOOLEAN MODE) AS `relevance` FROM `search_table` AS `s`
 WHERE (MATCH (s.data_index) AGAINST ('Hello' IN BOOLEAN MODE));

SELECT `s`.`fulltext_id`, MATCH (s.data_index) AGAINST ('abc' IN BOOLEAN MODE) AS `relevance` FROM `search_table` AS `s`
 WHERE (MATCH (s.data_index) AGAINST ('abc' IN BOOLEAN MODE));

只有第一个查询(搜索Test)会返回结果,其他两个不会。我不明白为什么?

1 个答案:

答案 0 :(得分:0)

您应该检查当前定义的停用词列表。你可以这样做:

mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_DEFAULT_STOPWORD;

有关MySQL停用词的更多信息,请访问:https://dev.mysql.com/doc/refman/5.7/en/fulltext-stopwords.html

例如,

Hello是一个已知的禁用词,因此在FTS匹配期间会被忽略。如果您在链接的MySQL文档页面上查看评论,您将找到从用户到英语语言停用词列表的链接,例如https://www.ranks.nl/stopwords/

注意,MySQL以及其他数据库引擎允许您指定自己的停用词自定义列表。因此,您应该检查预定义的系统停用词列表和任何现有的自定义停用词列表。