MySQL MATCH(字段)AGAINST('string')适用于某些人,不适用于其他人

时间:2015-06-02 16:39:27

标签: mysql

我有一个MYSQL表,如下所示:

phrase1    phrase2
ssd        solid state drive
ps 4       playstation 4

phrase1phrase2列都是FULLTEXT

我发出以下查询:

select * from phrases
where match(phrase1) against('ssd' IN BOOLEAN MODE)
OR match(phrase2) against('ssd' IN BOOLEAN MODE);

我回来了:

+----+-------------------+---------+
| id | phrase1           | phrase2 |
+----+-------------------+---------+
|  1 | solid state drive | ssd     |
+----+-------------------+---------+
1 row in set (0.00 sec)

但是当我发出时:

select * from phrases
where match(phrase1) against('ps 4' IN BOOLEAN MODE)
OR match(phrase2) against('ps 4' IN BOOLEAN MODE);

我明白了:

Empty set (0.00 sec)

以下是全文的一些变量。

> show variables like 'ft_%';
+--------------------------+----------------+
| Variable_name            | Value          |
+--------------------------+----------------+
| ft_boolean_syntax        | + -><()~*:""&| |
| ft_max_word_len          | 84             |
| ft_min_word_len          | 1              |
| ft_query_expansion_limit | 20             |
| ft_stopword_file         | (built-in)     |
+--------------------------+----------------+
5 rows in set (0.00 sec)

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

使用NATURAL LANGUAGE MODE搜索带空格的字符串。

https://dev.mysql.com/doc/refman/5.1/en/fulltext-natural-language.html

所以你的代码将是:

select * from phrases
where match(phrase1) against('ps 4' IN NATURAL LANGUAGE MODE)
OR match(phrase2) against('ps 4' IN NATURAL LANGUAGE MODE);

请告诉我这是否适合您