无法让MySQL全文搜索工作

时间:2011-03-02 22:26:00

标签: mysql search full-text-search

我有一张桌子,我希望能够进行全文搜索,但我似乎无法对搜索字词进行任何点击。

这是我的表格的样子(我拿出了一些我认为不重要的专栏):

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 个答案:

答案 0 :(得分:4)

默认情况下,全文忽略3个或更少字符的单词

(现在根据要求发布答案:))

答案 1 :(得分:3)

这是另外需要考虑的事情:

您不仅可以更改默认长度,还可以更改禁用词列表。您可能想要更改停用词,因为MySQL不会将this list of 543 words编入索引。 尝试创建自己的禁用词列表并更改最小字长。

步骤1)创建自己的停用词列表。你可以添加'a','an'和'the'。

echo“a”> /var/lib/mysql/custom_stopwords.txt
echo“an”>> /var/lib/mysql/custom_stopwords.txt
echo“the”>> /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)service mysql restart

步骤4)创建新的FULLTEXT索引。在重新启动mysql之前,任何现有的FULLTEXT索引都应该重新编制索引。

试一试!!!