我正在尝试实现完整的测试搜索。为此,我首先将/etc/mysql/my.cnf上的ft_min_word_len = 2
值更改为
[mysqld]
#
# * Basic Settings
#
#
# * IMPORTANT
# If you make changes to these settings and your system uses apparmor, you may
# also need to also adjust /etc/apparmor.d/usr.sbin.mysqld.
#
ft_min_word_len = 2
现在保存并重新启动服务器。
我知道,如果在表中已经有一个全文索引,则需要删除索引并重新生成,或修复表。
但是我已经创建了这个表
create table
`comments`
( `id` int(11),
`comment` varchar(200),
`iduser` int(11) ,
`date_added` datetime
)
ENGINE=MyISAM;
ALTER TABLE comments
ADD FULLTEXT INDEX comment_index
(comment);
然后在上表中,我手动添加了一些注释。
当我试图搜索
SELECT * FROM comments where MATCH (comment) AGAINST ('the') ; // "the" is very common word of length to see my test result
它返回0行。
然而,如果我用一个4字的长度来反对,它是有效的。
我试着用
mysql> show variables like 'ft_%';
+--------------------------+----------------+
| Variable_name | Value |
+--------------------------+----------------+
| ft_boolean_syntax | + -><()~*:""&| |
| ft_max_word_len | 84 |
| ft_min_word_len | 2 |
| ft_query_expansion_limit | 20 |
| ft_stopword_file | (built-in) |
+--------------------------+----------------+
有趣的是在
/etc/mysql/my.cnf
中我只能看到ft_min_word_len
,但是ft_max_word_len
不存在,更重要的是小于长度4的搜索不起作用。这让我抓狂,不确定是否有其他配置是过度编写的一切,似乎也无法找到他们。
任何帮助都将不胜感激。
我的开发机器中的Mysql版本是
mysql Ver 14.14 Distrib 5.1.63, for debian-linux-gnu (i686) using readline 6.2
最佳答案
我找到了问题和解决方法。
全文搜索设置很好,因为我想用alt east两个词搜索,并且我有ft_min_word_len = 2
现在,在做更多的测试时,我发现它会随机搜索几个2个字符的单词,而忽略其他单词。
下面是一个例子
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
);
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
mysql> SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('use');
Empty set (0.00 sec)
mysql> SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('Use');
Empty set (0.00 sec)
mysql> SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('you');
Empty set (0.00 sec)
mysql> SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('the');
Empty set (0.00 sec)
mysql> SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('vs.');
Empty set (0.00 sec)
但是下面的工作
mysql> SELECT * FROM articles
-> WHERE MATCH (title,body) AGAINST ('run');
+----+-------------------+-------------------------------------+
| id | title | body |
+----+-------------------+-------------------------------------+
| 4 | 1001 MySQL Tricks | 1. Never run mysqld as root. 2. ... |
+----+-------------------+-------------------------------------+
所以它是另一个东西,很明显找到了它的
ft_stopword_file
,它有一个单词列表,如果其中一个出现任何搜索,它不会做任何事情。名单在这里http://dev.mysql.com/doc/refman/5.1/en/fulltext-stopwords.html
因此在这种情况下,允许任何长度至少为2个字符的单词搜索
将ft_min_word_len设置为2
然后在mysql配置文件中,对于debian/etc/mysql/my.cnf,添加ft_stopword_file=/path/to/stopword_file.txt'
如果需要的话,我们可以把这个文件留空。
还有一件事,一旦我们完成了上述设置,我们需要重新启动mysql,如果我们更改了
ft_min_word_len
,那么我们需要重新构建索引或修复表。关于mysql - 在Ubuntu上的mysql ft_min_word_len更改不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21777749/