In Solr, is there a difference between the NOT and - (minus) operators? If so, what is it?
Solr documentation references the Lucene Query Parser Syntax, and it is vague on this matter. The two operators seem to function the same way, but it's not clear.
Solr's default Query Parser is also known as the “ lucene ” parser. The key advantage of the standard query parser is that it supports a robust and fairly intuitive syntax allowing you to create a variety of structured queries.
Solr queries require escaping special characters that are part of the query syntax. Special characters are: +, -, &&, ||, !, (, ), ", ~, *, ?, and : . To escape these characters, use a slash ( \ ) before the character to escape.
You can embed Boolean operators in a query string to improve the precision of a match. The full syntax supports text operators in addition to character operators. Always specify text boolean operators (AND, OR, NOT) in all caps.
To expand on Mauricio's answer (because the QueryParser class is some of the most confusing code I've ever read) if you look at lines 145-152 you'll see:
case MINUS:
jj_consume_token(MINUS);
ret = MOD_NOT;
break;
case NOT:
jj_consume_token(NOT);
ret = MOD_NOT;
break;
So they are both considered MOD_NOT
s.
The Lucene QueryParser code says they're equivalent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With