我有一个MYSQL表,如下所示:
phrase1 phrase2
ssd solid state drive
ps 4 playstation 4
phrase1
和phrase2
列都是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)
有什么建议吗?
答案 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);
请告诉我这是否适合您