I’m crashing into a weird behavior with – operators in Solr/Lucene query syntax.
If I execute the query
-text AND -text
I get all expected results (lot), but if I put some parenthesis like
-text AND (-text)
or
(-text) AND (-text)
then I get no results at all. I can’t understand why.
Do you have an explanation for this behavior?
Thank you in advance.
The question have been answered very well in
Solr mailing list. They have also added an entry in the offical FAQ, that says:
So expressions with only "negative" values return always 0 results, except at the topmost level, where the parser silently add a
*:*at the beginning of the query.Therefore
-text AND -textis transformed to*:* -text AND -textand so it has results, while(-text)isn’t transformed to(*:* -text), because it is not at the topmost level, and so(-text)gives no results.