Bug #31755 Full text phrase matching does not seem to support the NOT operator
Submitted: 22 Oct 2007 14:52 Modified: 21 Mar 2011 16:51
Reporter: Thomas Chin Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: FULLTEXT search Severity:S1 (Critical)
Version:5.0.44 OS:Linux (Gentoo)
Assigned to: Assigned Account CPU Architecture:Any

[22 Oct 2007 14:52] Thomas Chin
Description:
To whom it may concern:

I do not believe the NOT (-) operator works properly with phrases preserving the word order.  As part of my testing before filing this bug, I tested the phrase matching behavior in terms of OR and AND (+) operators to establish a baseline of expected behavior.  It seems that the NOT (-) operator does enforce the exclusion of rows containing words in the phrase, but the exclusion does not take order or location of the words into account (as the OR and AND (+) matching does).

Thank you for any assistance in this matter in advance.

Sincerely,
Thomas S. Chin

How to repeat:
mysql> CREATE TABLE test (data TEXT, FULLTEXT(data));
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO test VALUES ('foo bar');
Query OK, 1 row affected (0.00 sec)

mysql> -- expect 1 row
mysql> SELECT data FROM test WHERE MATCH(data) AGAINST('+"foo bar"' IN BOOLEAN MODE);
+---------+
| data    |
+---------+
| foo bar |
+---------+
1 row in set (0.00 sec)

mysql> -- expect empty
mysql> SELECT data FROM test WHERE MATCH(data) AGAINST('+"bar foo"' IN BOOLEAN MODE);
Empty set (0.00 sec)

mysql> -- expect 1 row
mysql> SELECT data FROM test WHERE MATCH(data) AGAINST('foo -"foo bars"' IN BOOLEAN MODE);
+---------+
| data    |
+---------+
| foo bar |
+---------+
1 row in set (0.00 sec)

mysql> -- expect 1 row (*** unexpected result ***)
mysql> SELECT data FROM test WHERE MATCH(data) AGAINST('foo -"bar foo"' IN BOOLEAN MODE);
Empty set (0.00 sec)

mysql> -- expect 1 row
mysql> SELECT data FROM test WHERE MATCH(data) AGAINST('foo -"bars foo"' IN BOOLEAN MODE);
+---------+
| data    |
+---------+
| foo bar |
+---------+
1 row in set (0.00 sec)

Suggested fix:
I believe the following query (in the provided example) should return 1 results:

SELECT data FROM test WHERE MATCH(data) AGAINST('foo -"bar foo"' IN BOOLEAN MODE);
[21 Feb 2011 16:51] MySQL Verification Team
Sorry for the delay. Could you please provide the output of:

show variables like "ft_min%";

Thanks in advance.
[22 Mar 2011 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".