MySQL停用词和匹配 [英] Mysql stop words and match
问题描述
我希望有人可以帮助我解决有关MYSQL停用词和匹配项的查询
I'm hoping someone can help with a query I have regarding MYSQL stopwords and match
如果我要运行以下mysql查询:
If I were to run the below mysql query:
CREATE TABLE `tbladvertstest` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT,`SearchCompany` varchar(250) DEFAULT NULL,PRIMARY KEY (`id`),FULLTEXT KEY `SearchCompany` (`SearchCompany`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `tbladvertstest` (`id`, `SearchCompany`) VALUES (NULL, 'All Bar One');
SELECT * FROM `tbladvertstest` WHERE MATCH (`SearchCompany`) AGAINST ('"All Bar One"' IN BOOLEAN MODE)
我认为查询将返回"SearchCompany"为"All Bar One"的所有结果,但返回的行数为零.我假设Mysql是逐个检查每个单词,而不是查看整个字符串,而停用词和最小单词长度是它不返回任何结果的原因?我说的对吗?如果可以的话,是否有可能让MySQL将其视为字符串?
I thought the query would return all results where 'SearchCompany' is "All Bar One" but there are zero rows returned. I'm assuming Mysql is checking against each word individually rather than looking at the full string and the stopwords and minium word lengths are the reason it not returning any results? Would I be right? If so is it possible to get MySQL to see it as a string?
推荐答案
默认情况下,MySQL FULLTEXT索引不会索引短于4个字符的单词(对于MyISAM表).如果要索引3个字母的单词,则需要设置 innodb_ft_min_token_size
设置为3或更低的值,然后重新启动mysqld并重建表.
By default, MySQL FULLTEXT indexes will not index words shorter than 4 characters long (for MyISAM tables). If you want to index 3 letter words, you need to set the ft_min_word_len
system variable (or innodb_ft_min_token_size
for InnoDB) to a value of 3 or lower, then restart mysqld and rebuild your table.
例如,将其添加到my.cnf文件的[mysqld]
部分:
For example, add this to the [mysqld]
section of your my.cnf file:
ft_min_word_len=3
然后重新启动mysqld.
Then restart mysqld.
然后运行以下命令来重建表:
Then run this command to rebuild the table:
alter table `tbladvertstest` force;
现在您的查询应该可以使用了:
Now your query should work:
mysql > SELECT *
-> FROM `tbladvertstest`
-> WHERE MATCH (`SearchCompany`) AGAINST ('+"All Bar One"' IN BOOLEAN MODE) ;
+----+---------------+
| id | SearchCompany |
+----+---------------+
| 1 | All Bar One |
+----+---------------+
1 row in set (0.00 sec)
这篇关于MySQL停用词和匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!