MySQL Search Query - “Keep” not working

强颜欢笑 提交于 2019-12-11 11:39:51

问题


Im a little confused with the follow query we have been using for a while, The following works

Search query for "fire"

SELECT product FROM product_descriptions WHERE MATCH(product) AGAINST('+fire*' IN BOOLEAN MODE) LIMIT 5

Returns

Fire Storage 31020 S1 E
Fire Storage 31020 S1 K
Fire Storage 31021 S1 E
Fire Storage 31021 S1 K
Fire Storage 31022 S1 E

However the following search query for "keep"

SELECT product FROM product_descriptions WHERE MATCH(product) AGAINST('+keep*' IN BOOLEAN MODE) LIMIT 5

Returns no results however we have products in table such as "Fire Door Keep Shut Sign", "Keep Clear Sign"

The only word that doesnt work i've found so far is the work "keep"

The following searches work "steel", "door" as i thought it maybe a problem with double characters


回答1:


Keep is a stop-word

Wikipedia:

In computing, stop words are words which are filtered out prior to, or after, processing of natural language data (text). [...] Some tools specifically avoid removing them to support phrase search. Any group of words can be chosen as the stop words for a given purpose. For some search machines, these are some of the most common, short function words, such as the, is, at, which, and on. In this case, stop words can cause problems when searching for phrases that include them, particularly in names such as 'The Who', 'The The', or 'Take That'. Other search engines remove some of the most common words—including lexical words, such as "want"—from a query in order to improve performance.

http://dev.mysql.com/doc/refman/5.1/en/fulltext-stopwords.html

You can find the actually used list in the storage/myisam/ft_static.c file.

This fact is stated in http://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html

You might want to use Lucene instead. It's list of stop-words is much smaller, plus you can remove them completely:
How to instruct StandardAnalyzer in Lucene to not to remove stop words?

Or you can add

ft_stopword_file = ""

or link an empty file "empty_stopwords.txt" to your .cnf/my.ini file, restart the mysql engine and rebuild the indices:

I addition to that, if you haven't allready, lower the min word to 3 (ft_min_word_len=3) to be able to search for 3 letter words.

Shorter words (3,2) will increase the query time dramatically, especially if the fulltext indexed column fields are large.



来源:https://stackoverflow.com/questions/24952900/mysql-search-query-keep-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!