Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql fulltext search not working with special characters

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 special characters.

Example: In the domains table, 'name' field have the following three values:

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

If i am using the search term https://www.google.com, it will show all the above three values as result but the correct answer is https://www.google.com.

Query:

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

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

like image 260
raj Avatar asked Oct 09 '15 10:10

raj


People also ask

What is full text search in MySQL?

A full-text index in MySQL is an index of type FULLTEXT . Full-text indexes can be used only with InnoDB or MyISAM tables, and can be created only for CHAR , VARCHAR , or TEXT columns.


1 Answers

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

A phrase that is enclosed within double quote (“"”) characters matches only rows that contain the phrase literally, as it was typed.

For example:

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 that * you can search for '"https://www.google.com*"' (* is put inside the double quote).

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

like image 93
Grzegorz Adam Kowalski Avatar answered Oct 07 '22 13:10

Grzegorz Adam Kowalski