MYSQL FULLTEXT search does not work with hypen '-' and plus '+'

别等时光非礼了梦想. 提交于 2019-12-11 09:55:00

问题


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:


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"


来源:https://stackoverflow.com/questions/33096544/mysql-fulltext-search-does-not-work-with-hypen-and-plus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!