MySQL全文布尔NOT运算符(mysql fulltext boolean NOT operator)

38 IT屋

I'm doing a MySQL FULLTEXT search in boolean mode. According to the manual :

Note: The - operator acts only to exclude rows that are otherwise 
matched by  other search terms. Thus, a boolean-mode search that 
contains only terms preceded by - returns an empty result. It 
does not return “all rows except those containing any of the 
excluded terms.”

That's true.

So I use the NOT MATCH operator like this :

SELECT COUNT(*) FROM Table WHERE MATCH (Column) AGAINST 
('bar' IN BOOLEAN MODE) AND NOT MATCH (Column) AGAINST 
('barbar' IN BOOLEAN MODE);

My question is: what is the effect of the + operator in the NOT MATCH field: is

AND NOT MATCH (Column) AGAINST ('foo bar' IN BOOLEAN MODE)

the same as :

AND NOT MATCH (Column) AGAINST ('+foo +bar' IN BOOLEAN MODE)

Thanks

解决方案

+ operator signifies that the search literal is present. Per MySQL Documentation

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 example, below query will retrieves all the rows that contain the word MySQL but that do not contain the word YourSQL

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

+ A leading plus sign indicates that this word must be present in each row that is returned.

EDIT:

WHERE NOT MATCH (column) AGAINST ('+foo +bar' IN BOOLEAN MODE) should mean get me all the rows where values of column isn't foo and bar. it should be a negation of WHERE MATCH (column) AGAINST ('+foo +bar' IN BOOLEAN MODE)

Yes, both are not same.

WHERE MATCH (column) AGAINST ('+foo +bar' IN BOOLEAN MODE)

Says that get all rows where values of column are foo and bar

WHERE MATCH (column) AGAINST ('foo bar' IN BOOLEAN MODE)

Says that get all rows where values of column are foo or bar

Check the documentation carefully. It says

[no operator] implies OR

[+] implies AND

我正在以布尔模式进行MySQL FULLTEXT搜索。根据手册:



 注意:-运算符仅用于排除其他搜索匹配
的行条款。因此,布尔模式搜索
仅包含以-开头的术语时,将返回空结果。
不会返回"除包含
中任何排除条款的行以外的所有行。"


是的。



所以我这样使用NOT MATCH运算符:



  SELECT从表中的COUNT(*)匹配
(在BOOLEAN模式下为" bar")而不匹配(列)在
(在BOOLEAN模式下为" barbar");


我的问题是:NOT匹配字段中+运算符的作用是什么



 并且不匹配(列)反对('foo bar'在布尔模式下)
< / pre>

与:



 相同且不匹配(列)反对('+ foo + bar'在布尔模式下)


谢谢


解决方案

+ 运算符表示存在搜索文字。每个 MySQL文档




MySQL可以使用IN BOOLEAN MODE
修饰符执行布尔型全文本搜索。使用此修饰符,某些字符在搜索字符串中单词的开头或结尾具有特殊含义
。在下面的
查询中, + -运算符表示一个单词是
,需要存在或不存在




例如,下面的查询将检索包含单词 MySQL ,但不包含单词 YourSQL



  SELECT *摘自文章"匹配"(标题,正文)
反对(" + MySQL -YourSQL"(布尔模式));



+
前导加号表示该单词必须出现在返回的每个
行中。




EDIT:



反对(列)反对('+ foo + bar'在BOOLEAN模式下)的意思是让我了解所有包含值的行的列不是 foo 和 bar 。应该是,反对(列)反对(" + foo + bar"在布尔模式下) < / p>

是的,两者都不相同。



 在哪里匹配(列)反对('+ foo + bar'在BOOLEAN模式下)


表示所有列的值都表示为行是foo和bar



 在哪里匹配(列)反对(" foo bar"在布尔模式下)


表示所有列的值为foo或bar的行



仔细检查文档。它说




[无运算符]表示OR



[+]表示AND



本文地址:IT屋 » MySQL全文布尔NOT运算符