views:

4127

answers:

4

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?

+4  A: 

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!

Mauricio Scheffer
Thank you for your help! This does indeed work - and I have posed this to the solr-user group. I'll post any useful things I hear from them here.
stolenricecakes
+1  A: 

You can find the follow up to the solr-user group on: solr user mailling list

The prevailing thought is that the NOT operator may only be used to remove results from a query - not just exclude things out of the entire dataset. I happen to like the syntax you suggested mausch - thanks!

stolenricecakes
A: 
Instead of NOT <condition> use (*:* NOT <condition>)
MVMn
A: 
Instead of "NOT [condition]" use "(*:* NOT [condition])"
MVMn