布尔模式下的MySQL Match Against在中间单词上不返回任何内容 [英] MySQL Match Against In Boolean Mode returns nothing on middle word

查看:282
本文介绍了布尔模式下的MySQL Match Against在中间单词上不返回任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MySQL数据库中使用Match Match时遇到问题,希望有人能提供帮助.

这是我数据库中数据的示例:

id   name
1    really bitter chocolate
2    soft cheese

当我运行此查询时:

SELECT * FROM food WHERE (name) LIKE "%bitter%"

这带来了第一个结果:

1    really bitter chocolate

无论如何它是更大查询的一部分,并且当我运行匹配条件"代码时,这些查询中的任何一个都无法返回任何内容:

SELECT * FROM food WHERE MATCH (name) AGAINST ("bitter")

SELECT * FROM food WHERE MATCH (name) AGAINST ("bitter", IN BOOLEAN MODE)

我打开了全文搜索,当我搜索名字的开头时,它可以工作:

SELECT * FROM food WHERE MATCH (name) AGAINST ("really")

SELECT * FROM food WHERE MATCH (name) AGAINST ("really", IN BOOLEAN MODE)

两者均返回:

1    really bitter chocolate

我已阅读以下解决方案: http://dev.mysql.com/doc/refman/5.5/zh-CN/fulltext-boolean.html

我看过这里: mysql在哪里匹配

有人可以看到我要去哪里或向正确的方向指出吗?

谢谢!

编辑

按照下面的Woot4Moo很好的答案,好吧,我更改了代码以删除不应该出现的逗号.我还添加了+并将其放在单引号中,但仍然没有运气.

我当前的查询现在看起来像这样:

SELECT * FROM food WHERE MATCH (name) AGAINST ('+bitter' IN BOOLEAN MODE)

但是在查询浏览器中没有返回任何结果,也没有返回任何错误或警告.

解决方案

SELECT * FROM food WHERE MATCH (name) AGAINST ("bitter", IN BOOLEAN MODE)

看起来应该是:

SELECT * FROM food WHERE MATCH (name) AGAINST ('+bitter' IN BOOLEAN MODE)  

注意我的加号 +无逗号 ,

根据示例此处

MySQL可以使用IN BOOLEAN执行布尔全文搜索 模式修改器.使用此修饰符,某些字符具有特殊 意思是搜索字符串中单词的开头或结尾.在里面 查询后,+和-运算符表示一个单词是 必须分别存在或不存在,才能进行匹配. 因此,查询将检索包含单词"MySQL"的所有行. 但其中不包含"YourSQL"一词:

mysql> SELECT * FROM articles WHERE MATCH (title,body)
    -> AGAINST ('+MySQL -YourSQL' IN BOOLEAN MODE);

I've got a problem using Match Against in my MySQL database, and I'm hoping someone can help.

This is the examples of the data in my database:

id   name
1    really bitter chocolate
2    soft cheese

When I run this query:

SELECT * FROM food WHERE (name) LIKE "%bitter%"

This bring back the first result:

1    really bitter chocolate

However its part of a much larger query, and when I run the Match Against code, I don't get anything returned from either of these queries:

SELECT * FROM food WHERE MATCH (name) AGAINST ("bitter")

SELECT * FROM food WHERE MATCH (name) AGAINST ("bitter", IN BOOLEAN MODE)

I have full text searches turned on, and it works when I search the start of the name:

SELECT * FROM food WHERE MATCH (name) AGAINST ("really")

SELECT * FROM food WHERE MATCH (name) AGAINST ("really", IN BOOLEAN MODE)

Both of which returns:

1    really bitter chocolate

I've read through this for solutions: http://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html

And I've looked here: mysql WHERE MATCH AGAINST

Can someone please see where I am going wrong or point me in the right direction?

Thanks!

EDIT

Ok as per Woot4Moo great answer below I've changed my code to remove the comma which shouldn't have been there. I've also added in the + and putting it in single quotes but still no luck.

My current query now looks like this:

SELECT * FROM food WHERE MATCH (name) AGAINST ('+bitter' IN BOOLEAN MODE)

But it's returning no results in query browser, and not returning any errors or warnings.

解决方案

SELECT * FROM food WHERE MATCH (name) AGAINST ("bitter", IN BOOLEAN MODE)

looks like it should be:

SELECT * FROM food WHERE MATCH (name) AGAINST ('+bitter' IN BOOLEAN MODE)  

notice how mine has the plus sign + and NO comma ,

Basing it off of the example here

MySQL can perform boolean full-text searches using the IN BOOLEAN MODE modifier. With this modifier, certain characters have special meaning at the beginning or end of words in the search string. In the following query, the + and - operators indicate that a word is required to be present or absent, respectively, for a match to occur. Thus, the query retrieves all the rows that contain the word "MySQL" but that do not contain the word "YourSQL":

mysql> SELECT * FROM articles WHERE MATCH (title,body)
    -> AGAINST ('+MySQL -YourSQL' IN BOOLEAN MODE);

这篇关于布尔模式下的MySQL Match Against在中间单词上不返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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