MYSQL FULLTEXT search does not work with hypen 

2019-08-08 03:56发布

Issue: I am using the MYSQL and PHP latest versions. We are facing the issue in the MYSQL FULLTEXT search. It does not work with the hypen(-) and plus(+) characters.

Example:1 In the industry table, 'industry_size' field have the following values:

 1. 1
 2. 2 - 9
 3. 10 - 15

If i am using the search term 2 - 9, it will show the empty result but the correct answer is 2 - 9.

Example:2 In the user table, 'phone_number' field have the following values:

 1. 9856237845
 2. +91 8945785698
 3. +91 7489569878

If i am using the search term +91 89, it will show the empty result but the correct answer is +91 8945785698.

Kindly advise. Thanks in advance.

1条回答
Evening l夕情丶
2楼-- · 2019-08-08 04:30

You need to use *. The documentation says:

The asterisk serves as the truncation (or wildcard) operator. Unlike the other operators, it should be appended to the word to be affected. Words match if they begin with the word preceding the * operator.

Try this:

MATCH(field) AGAINST("+91 89*" IN BOOLEAN MODE)

or you can use Binary operator

where BINARY your_column = BINARY "2-9"
查看更多
登录 后发表回答