2011-03-02 96 views
1

我有一張桌子,我希望能做全文搜索,但我似乎無法得到我的搜索條件任何點擊。不能讓MySQL全文搜索工作

這裏是我的表是什麼樣子(我拿出行動,我相信都不重要了幾列):

mysql> SHOW TABLE STATUS LIKE 'transcripts'; 
+-------------+--------+---------+------------+-------------------+----------+----------------+ 
| Name  | Engine | Version | Row_format | Collation   | Checksum | Create_options | 
+-------------+--------+---------+------------+-------------------+----------+----------------+ 
| transcripts | MyISAM |  10 | Dynamic | latin1_swedish_ci |  NULL |    | 
+-------------+--------+---------+------------+-------------------+----------+----------------+ 

mysql> DESCRIBE transcripts; 
+-------------+----------+------+-----+---------+----------------+ 
| Field  | Type  | Null | Key | Default | Extra   | 
+-------------+----------+------+-----+---------+----------------+ 
| id   | int(11) | NO | PRI | NULL | auto_increment | 
| content  | text  | YES |  | NULL |    | 
| raw_content | text  | YES | MUL | NULL |    | 
| tape_id  | int(11) | YES |  | NULL |    | 
| state  | int(11) | YES |  | 0  |    | 
| created_at | datetime | YES |  | NULL |    | 
| updated_at | datetime | YES |  | NULL |    | 
+-------------+----------+------+-----+---------+----------------+ 

mysql> SHOW INDEXES FROM transcripts; 
+-------------+------------+-------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+ 
| Table  | Non_unique | Key_name   | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | 
+-------------+------------+-------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+ 
| transcripts |   0 | PRIMARY   |   1 | id   | A   |   2 |  NULL | NULL |  | BTREE  | 
| transcripts |   1 | raw_content_index |   1 | raw_content | NULL  |  NULL |  NULL | NULL | YES | FULLTEXT | 
+-------------+------------+-------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+

證明,有一排發現:

mysql> SELECT id, raw_content FROM transcripts; 
+----+-------------+ 
| id | raw_content | 
+----+-------------+ 
| 1 | foo   | 
+----+-------------+

而且這裏是我試圖讓搜索工作:

mysql> SELECT * FROM transcripts WHERE MATCH(raw_content) AGAINST ('foo'); 
Empty set (0.00 sec) 

mysql> SELECT * FROM transcripts WHERE MATCH(raw_content) AGAINST ('foo' IN BOOLEAN MODE); 
Empty set (0.00 sec) 

mysql> SELECT id FROM transcripts WHERE MATCH(raw_content) AGAINST ('foo' IN NATURAL LANGUAGE MODE); 
Empty set (0.00 sec) 

mysql> SELECT * FROM transcripts WHERE MATCH(raw_content) AGAINST ('+foo*' IN BOOLEAN MODE); 
Empty set (0.00 sec)

我在做什麼錯?

+2

默認全文忽略帶3個或更少字符的單詞 – Cfreak 2011-03-02 22:28:10

+0

Bah,就是@Cfreak。你可以把它作爲答案嗎?布爾模式搜索使用更長的搜索。 – muirbot 2011-03-02 22:35:02

+1

如果您搜索至少50%記錄中存在的單詞,請注意不使用布爾模式,將忽略它。更多信息在這裏http://dev.mysql.com/doc/refman/5.1/en/fulltext-fine-tuning.html問候;) – 2011-03-02 22:39:38

回答

4

默認全文忽略單詞,3點或更少的字符

(現已公佈作爲一個答案按要求:))

3

這裏是別的東西來考慮:

你不僅可以改變默認長度,但您也可以更改停用詞列表。您可能想要更改停用詞,因爲MySQL不會索引this list of 543 words。 嘗試創建您自己的停用詞列表並更改最小字長度。

第1步)創建一個你自己的停止詞列表。你可以添加'a','an'和'the'。

回聲 「一」> /var/lib/mysql/custom_stopwords.txt
回聲 「一個」 >> /var/lib/mysql/custom_stopwords.txt
回聲 「該」 >>的/ var/lib中/ MySQL的/ custom_stopwords.txt

步驟2)添加這些選項來在/etc/my.cnf

的ft_min_word_len = 2
ft_stopword_file =的/ var/lib中/ MySQL的/ custom_stopwords.txt

步驟3)服務mysql重啓

第4步)創建新的FULLTEXT索引。在重新啓動mysql之前,任何現有的FULLTEXT索引都應重新編制索引。

試試吧!

+0

非常有幫助,謝謝! – muirbot 2011-03-03 04:50:32