如何在 Sphinx 中使用 NOT?

How to use NOT in Sphinx?

Documentation 说:

WHERE clause. This clause will map both to fulltext query and filters. Comparison operators (=, !=, <, >, <=, >=), IN, AND, NOT, and BETWEEN are all supported and map directly to filters

但是当我尝试使用下一个查询 select 数据时,我遇到了麻烦:

mysql> select * from content where NOT sentiment = 1;
ERROR 1064 (42000): sphinxql: syntax error, unexpected NOT, expecting IDENT (or 56 other tokens) near 'NOT sentiment = 1'

怎么了?

NOT 是一个运算符,通常与另一个运算符结合使用,例如 IN 或在处理布尔值或 NULL;

有效示例:

SELECT * FROM content WHERE sentiment IS NOT TRUE;
SELECT * FROM content WHERE sentiment IS NOT NULL;
SELECT * FROM content WHERE sentiment NOT IN (1, 2);
SELECT * FROM content WHERE sentiment NOT BETWEEN 1 AND 5;

您也可以将其用作逻辑 NOT,它将反转零值和非零值:

SELECT NOT (1+3); /* 0 */
SELECT NOT 0;     /* 1 */

您的查询应使用 !=<> 运算符:

SELECT * FROM content WHERE sentiment != 1;
SELECT * FROM content WHERE sentiment <> 1;