简体   繁体   English

当包含单词“ of”时,为什么此MySQLquery返回零结果?

[英]Why does this MySQLquery return zero results when the word “of” is included?

This query is returning zero results when it includes +of in the search terms: 当查询字词中包含+of时,该查询将返回零结果:

SELECT DISTINCT *
        FROM pin
        WHERE MATCH (
        title, 
        front, 
        back, 
        price, 
        sku, 
        datereleased, 
        edition, 
        wherefrom, 
        class, 
        categories, 
        details, 
        groups, 
        associated, 
        artist) 
        AGAINST ('+Pirates +of +the +Caribbean' IN BOOLEAN MODE)
        ORDER BY pin.id DESC

Yet when I take it out, I get 1000+ rows: 但是,当我将其取出时,会得到1000多个行:

'+Pirates +the +Caribbean'

Also, when I search with a phrase instead, I get 1000+ rows: 另外,当我用短语搜索时,会得到1000多个行:

"Pirates of the Caribbean"

Why is the +of showing zero results? 为什么+of显示零结果? Are two character search words causing a problem in some way I am unaware of? 两个字符搜索词是否以某种我不知道的方式引起了问题? I've noticed the same issues with the word +to as well. 我也注意到+to单词也存在同样的问题。

If you want the word "of" to be included in fulltext searches there are two things you must do 如果要在全文搜索中包括“ of”一词,则必须做两件事

Set minimum word length 设置最小字长

You will have to set the ft_min_word_len to 1, by adding this to my.cnf 您必须将ft_min_word_len设置为1,方法是将其添加到my.cnf

[mysqld]
ft_min_word_len = 1

Include more common words 包含更多常用词

I wrote a post in the DBA StackExchange on Jan 26, 2012 about defining stopwords . 于2012年1月26日在DBA StackExchange上发表了有关定义停用词的文章

By default, there are 543 built-in words considered common. 默认情况下, 有543个内置单词被视为通用单词

Suggestion 建议

To create a stopword list, just make a text file and define it in my.cnf 要创建停用词列表,只需制作一个文本文件并在my.cnf定义它

To define the three Enlglish articles as stopwords, go to the OS and run this: 要将三篇Enlglish文章定义为停用词,请转到操作系统并运行以下命令:

echo "a"    > /var/lib/mysql/stopwords.txt
echo "an"  >> /var/lib/mysql/stopwords.txt
echo "the" >> /var/lib/mysql/stopwords.txt
chown mysql:mysql /var/lib/mysql/stopwords.txt

If you want all words, including a , an , and the , do this: 如果您想要包括aanthe所有单词,请执行以下操作:

echo -n > /var/lib/mysql/stopwords.txt
chown mysql:mysql /var/lib/mysql/stopwords.txt

Next, add these lines to my.cnf 接下来,将这些行添加到my.cnf

[mysqld]
ft_min_word_len=1
ft_stopword_file=/var/lib/mysql/stopwords.txt

Next, run service mysql restart 接下来,运行service mysql restart

Finally, reindex the pin table like this: 最后,像这样重新索引pin表:

REPAIR TABLE pin QUICK;

Give it a Try !!! 试试看 !!!

I found the answer to my issue. 我找到了问题的答案。 Looks like FULLTEXT index searches have a ft_min_word_len value defaulted at 4 character words. 看起来FULLTEXT索引搜索的ft_min_word_len值默认为4个字符。 I'll need to change it and rebuild my indexes if I want to search on smaller works. 如果要搜索较小的作品,则需要更改它并重建索引。

Reference: http://dev.mysql.com/doc/refman/5.5/en/fulltext-fine-tuning.html 参考: http : //dev.mysql.com/doc/refman/5.5/en/fulltext-fine-tuning.html

Also (thanks Dan Bracuk): 另外(感谢Dan Bracuk):

words that are present in 50% or more of the rows are considered common and do not match. 出现在50%或更多行中的单词被视为常见单词,不匹配。

Reference: http://dev.mysql.com/doc/refman/5.5/en/fulltext-search.html 参考: http : //dev.mysql.com/doc/refman/5.5/en/fulltext-search.html

I didn't know so I looked it up. 我不知道,所以我查了一下。 Found this page . 找到此页面 It includes this phrase: 它包括以下短语:

In addition, words that are present in 50% or more of the rows are considered common and do not match. 另外,出现在50%或更多行中的单词被认为是通用的,并且不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM