忽略查询中的mysql全文停用词 [英] ignoring mysql fulltext stopwords in query

查看:97
本文介绍了忽略查询中的mysql全文停用词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个网站的搜索,它使用全文搜索。搜索本身很好,这不是我的问题。我将用户提供的关键字(MATCH ... AGAINST ...)与AND结合在一起,以便多个单词进一步缩小结果范围。现在,我知道某些停用词没有编入索引,这对我来说很好,我不想将它们用作选择标准。但是,如果在关键字集中(由用户)提供了停用词,即使该词实际上位于某个文本块中,它也会杀死所有结果(如预期的那样)。



我的问题:是否有任何方法可以检查某个单词在查询时是否是停用词?我的首选解决方案就是从搜索条件中排除相关单词(我不关心用户是否可以用'none'来缩小结果,我只是不希望MySQL返回空的结果集,因为用户提供它,尽管结果中不存在)。或者,我只需要清空停用词表?非常感谢您的帮助。



编辑----
对不起,但这里没有提供代码片段。代码工作正常,实际上正如预期的那样。这是我正在处理的一个逻辑问题。但举例来说,以解释的方式:

可以说有三条记录,包括单词(但不限于)



1:苹果,橙子,芒果,香蕉
2:葡萄,橙子,菠萝,芒果
3:马铃薯,芒果,甜瓜,凯拉骑士

b
$ b

如果用户输入的搜索词是芒果,则所有结果都会正确返回。如果单词是橙色和芒果,结果1和2将被返回(正确)。现在,让我们说,香蕉是一个停止词(不是......但假设它是),如果搜索是橙色,芒果和香蕉,则不会返回结果(因为香蕉不在全文索引中)。

我在寻找的是其他人是否遇到过这个问题,并且有办法解决这个问题。排序:

 如果'banana'NOT STOP WORD'banana'与'words'匹配。 (显然不是真正的代码)。 

或者...我只需要放弃停用词列表...

解决方案

您可以通过比较所有停用词来验证关键字。以下是停用词
I的清单已经找到了一个解决方案来停用全文的停用词。
您只需要找到.cnf文件并添加它即可。

  ft_stopword_file =
code>

重启mysql引擎并重建索引;

希望这项工作

p>

I'm building a search for a site, which utilizes a fulltext search. The search itself works great, that's not my problem. I string together user provided keywords (MATCH... AGAINST...) with AND's so that multiple words further narrow the results. Now, I know that certain stop words aren't indexed, and that's fine with me I don't really want to use them as selection criteria. But, if a stopword is provided in the keyword set (by the user), it kills all the results (as expected) even if the word actually is in a certain text block.

My question: is there any way to check to see if a certain word is a stop word at the time of the query? My preferred solution would just be to exclude the relevant word from the search criteria (I don't care if a user can narrow results by the word 'neither', I just don't want MySQL to return an empty result set because the user provided it, even though neither does exist in the results). Or, am I just going to have to empty the stopword list? Thanks very much for any help.

edit ---- I'm sorry, but there's really no code snippets to provide for this one. The code works fine, actually exactly as expected. It's more of a logical problem I'm dealing with. But as an example, in the way of explanation:

lets say there are three records, which include the words (but are not limited to)

1: apple, orange, mango, banana 2: grape, orange, pineapple, mango 3: potato, mango, melon, keira knightly

If the search word entered by the user is mango, all results are returned correctly. If the words are orange AND mango, results 1 and 2 are returned (correctly). Now, let's say banana is a stop word (it's not... but let's assume it is), if the search is for orange, mango, AND banana, no results are returned (because banana isn't in the fulltext index).

What I'm looking for is if anyone else has encountered this problem, and has a way to work around it. Sort of an:

if 'banana' NOT STOP WORD match 'banana' against `words`. (OBVIOUSLY not real code).

Or... am I just going to have to drop the stopword list...

解决方案

You can verify the keywords by comparing all stopwords. Here is the list of stopwords I've found out a solution to disable stopwords from fulltext. You just need to locate .cnf file and add this,

ft_stopword_file = ""

restart mysql engine and rebuild indexes;

Hope this work

这篇关于忽略查询中的mysql全文停用词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆