问题
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
回答1:
+
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
来源:https://stackoverflow.com/questions/30696291/mysql-fulltext-boolean-not-operator