Skip to content
Advertisement

Full Text Search on MySQL : Can not search by word after hyphen/dash

I have the following record in DB: ‘Vinyl Exam – CA Only’

So, when I performed the following search:

SELECT  Description
            FROM    products AS p
            WHERE   MATCH (Description) AGAINST ('+Vinyl* +Only*' IN BOOLEAN MODE);

Record is returned, but in this case:

SELECT  Description
            FROM    products AS p
            WHERE   MATCH (Description) AGAINST ('+Vinyl* +Only* +CA*' IN BOOLEAN MODE);

Item is not returned.

What I should do to return the item in the last case.

Advertisement

Answer

The reason your search isn’t working is because by default, there’s a minimum length limit for words that can be searched using full text. As far as I remember, it’s 3 characters min for InnoDB and 4 characters min for MyISAM.

Since your word CA is only 2 characters long, it will be ignored in search. You can increase/decrease this character limit by changing the mysql settings.

Basically you need to add following config in your mysql my.cnf file (depending upon your database table engine):

[mysqld]
innodb_ft_min_token_size=2
ft_min_word_len=2

Find more details here.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement