Mysql full text search does not work with special characters

Problem: I use the latest versions of MYSQL and PHP. We are facing a problem in finding MYSQL FULLTEXT. It does not work with special characters.

Example. In the Domains table, the name field has the following three meanings:

1. https://www.google.com 2. https://www.yahoo.com 3. https://www.trafe.com 

If I use the search term https://www.google.com , it will display all of the above three values โ€‹โ€‹as a result, but the correct answer is https://www.google.com.

Request:

 SELECT name FROM domains WHERE MATCH (name) AGAINST ('https://www.google.com*' IN BOOLEAN MODE); 

Actual result: https://www.google.com

+5
source share
1 answer

Use a double quote: https://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html

The phrase enclosed in double quotation marks ("") matches only strings containing the letter literally as it was printed.

For instance:

 SELECT name FROM domains WHERE MATCH (name) AGAINST ('"https://www.google.com"' IN BOOLEAN MODE); 

Result:

 name https://www.google.com 

If you really want * you can search for '"https://www.google.com*"' ( * put in double quotation marks).

Here is the SQL script: http://sqlfiddle.com/#!9/a6458/6

+1
source

Source: https://habr.com/ru/post/1233338/


All Articles