using OR and NOT in solr query
I'm working on a solr query similar to the following:
((myField:superneat AND myOtherField:somethingElse) OR NOT myField:superneat)
When running this, no results are returned. Using criteria on either side of the OR NOT returns results that I'd expect - they are just not working well together. In the case that myField matches superneat, I'm intending to also ensure that myOtherField is set to somethingElse, but if myField is not superneat, include it in the results.
Can someone explain why solr is not returning results for this kind of query? Should the query be restructured somehow - or is there a different way in which solr can be used to achieve the desired result?
Solution 1:
I don't know why that doesn't work, but this one is logically equivalent and it does work:
-(myField:superneat AND -myOtherField:somethingElse)
Maybe it has something to do with defining the same field twice in the query...
Try asking in the solr-user group, then post back here the final answer!
Solution 2:
Instead of "NOT [condition]" use "(*:* NOT [condition])"