2014-08-28 178 views
0

如果我搜索單詞hello然後我沒有匹配,而我搜索單詞hella然後我得到了比賽。單詞Non發生同樣的事情。我在Mac和sqlfiddle.com上的MAMP上進行了測試,結果相同。你知道爲什麼嗎? 下面是測試:http://sqlfiddle.com/#!2/40658/1FULLTEXT mysql搜索不工作

CREATE TABLE IF NOT EXISTS `product` (
    `id` mediumint(8) unsigned NOT NULL auto_increment, 
    `name` TEXT default NULL, 
    PRIMARY KEY (`id`) 
) ENGINE=MyISAM AUTO_INCREMENT=1; 

INSERT INTO `product` (`name`) VALUES ("hello SANYO MC-1234"); 
INSERT INTO `product` (`name`) VALUES ("hella SANYO MC-1234"); 
INSERT INTO `product` (`name`) VALUES ("Non SONY"); 
INSERT INTO `product` (`name`) VALUES ("mac SONY"); 

拿到1場:

SELECT *, MATCH (`name`) AGAINST ('+hella*' IN BOOLEAN MODE) as `score` FROM `product` WHERE MATCH (`name`) AGAINST ('+hella*' IN BOOLEAN MODE) ORDER BY `score` DESC 

得到0的比賽:

SELECT *, MATCH (`name`) AGAINST ('+hello*' IN BOOLEAN MODE) as `score` FROM `product` WHERE MATCH (`name`) AGAINST ('+hello*' IN BOOLEAN MODE) ORDER BY `score` DESC 

回答

1

如果你要使用全文搜索,你需要學習關於停用詞和最小字長。

要開始的地方是documentation

簡短的回答是,「你好」是一個默認停用詞(如記錄here)。而且,短於4個字符的單詞被忽略(如「非」)。默認的最小字長度記錄爲4 here

+0

我明白了。謝謝! – user3985030 2014-08-28 02:36:23