开发者

MySQL MATCH...AGAINST sometimes finds answer, sometimes doesn't

The following two queries return the same (expected) result when I query my database:

SELECT * FROM articles 
 WHERE content LIKE '%Euskaldunak%'

SELECT * FROM articles 
 WHERE MATCH (content) AGAINST ('+"Euskaldunak"' IN BOOLEAN MODE)

The text in the content field that it's searching looks like this: "...These Euskaldunak, or newcomers..."

However, the following query on the same table returns the expected single result:

SELECT * FROM articles 
 WHERE content LIKE '%PCC%'

And the following query returns an empty result:

SELECT * FROM articles 
 WHERE MATCH (content) AGAINST ('+"PCC"' IN BOOLEAN MODE)

The text in the content field that matches this result looks like this: "...Portland Community College (PCC) is the largest..."

I can't figure out why searching for "Euskaldunak" works with that MATCH...AGAINST syntax but "PCC" doesn't. Does anyone see something that I'm not seeing?

(Also: "PCC" is not a common phrase in this field - no ot开发者_运维知识库her rows contain the word, so the natural language search shouldn't be excluding it.)


Your fulltext minimum word length is probably set too high. I think the default is 4, which would explain what you are seeing. Set it to 1 if you want all words indexed regardless of length.

Run this query:

show variables like 'ft_min_word_len';

If the values is greater than 3 and you want to get hits on words shorter than that, edit your /etc/my.cnf and add or update this line in the [mysqld] section using a value appropriate for your application:

ft_min_word_len = 1

Then restart MySQL and rebuild your fulltext indexes and you should be all set.


There are two things I can think of right away. The first is your ft_min_word_len value is set to more than 3 characters. Any "word" less than the ft_min_word_len length will not get indexed.

The second is that more then 50% of your records contain the 'PCC' string. A full text search that matches more than 50% of the records is considered irrelevant and returns nothing.

Full text indexes have different rules than regular string indexes. For example, there is a stop words list so certain common words like to, the, and, don't get indexed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜