Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full text query with a single quote

I'm having a problem when I try to do a full text search in boolean mode using a string with a single quote and an asterisk wildcard, i.e. "levi's*": it seems to search also for all words beginning with "s", like "spears", when, as far as I know, the quote should be considered part of the word while two single quotes ('') would be a word separator... but maybe I'm wrong.

Please, look at the example here: http://www.sqlfiddle.com/#!2/3dd3e/2/0 - the second row should't be there

how can I do what I want?

like image 502
Borgtex Avatar asked Sep 07 '12 10:09

Borgtex


2 Answers

I guess you should double quote the string you need to search for if it contains single quotes

Eg: MATCH(value) AGAINST ('"levi\'s"* lacost*' IN BOOLEAN MODE)

like image 117
Mihai Iorga Avatar answered Nov 17 '22 01:11

Mihai Iorga


this gives you the two rows from your example:

SELECT  *
FROM    ft
WHERE   MATCH(value) AGAINST ('"levi\'s" lacost*' IN BOOLEAN MODE)

In http://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html at the end, it talks about exact matches in double quotes. You then just escape the single quote and you are done.

Using parentheses, you can add the asterisk:

WHERE   MATCH(value) AGAINST ('(levi\'s)* lacost*' IN BOOLEAN MODE)
like image 2
Bart Friederichs Avatar answered Nov 17 '22 01:11

Bart Friederichs