我正在尝试实施完整的测试搜索。为此,我做的第一件事是将/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
现在保存并重新启动服务器。 我知道如果我已经在表中有一个FULLTEXT索引,我将需要删除索引并重建或修复表。 但我创建了表格
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的AGAINST设置为有效。
我试图将ft_变量检查为
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
答案 0 :(得分:3)
我能够找到问题和修复。
全文搜索设置很好,因为我想用alt east 2字搜索,我有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个字符的单词搜索
还有一件事,一旦我们完成上述设置,我们需要重新启动mysql,如果我们更改ft_min_word_len
,那么我们需要重新构建索引或修复表。