2014-02-14 40 views
1

我正在嘗試執行完整的測試搜索。而這樣做的第一件事,我做了/etc/mysql/my.cnf改變ft_min_word_len = 2值作爲mysql ft_min_word_len在Ubuntu上更改不起作用

[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行。

但是,如果我將AGAINST設置爲4的字長,它就可以工作。

我試圖檢查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_lenft_max_word_len是不存在的,更重要的是搜索不到長度4不atall工作。

這讓我瘋狂,不知道是否有其他配置寫過所有內容,似乎也找不到它們。

任何幫助,將不勝感激。

MySQL版本在我的機器是

mysql Ver 14.14 Distrib 5.1.63, for debian-linux-gnu (i686) using readline 6.2 

回答

3

我能夠發現問題,並修復。

全文搜索設置是好的,因爲我想與ALT東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個字符長

  • 設置的ft_min_word_len到2
  • 然後在mysql的配置文件, for debian /etc/mysql/my.cnf add ft_stopword_file ='path/to/stopword_file.txt'
  • 如果需要,我們可以將此文件留空。

哦,還有一兩件事,一旦我們做了上面的設置,我們需要重新啓動mysql的,如果我們改變ft_min_word_len那麼我們就需要重新建立索引或修復表。