Complex SOLR query including NOT and OR

I have quite complicated SOLR search requirements that I need to fulfill for my database with tagged content. I need to first filter the database for those results that match my filter tags. Any of these results that have a blacklist tag should be removed if they also do not contain white list tags.

So, let's say I want to get all the documents with the tags "forest" or "conservation". But I want to exclude documents with the tags "uk" or "europe" - unless they are also marked with "africa" ​​or "asia". I tried to write this in my SOLR request:

tag:((forest OR conservation) AND (africa OR asia OR !uk OR !europe)) 

The logic seems sound to me, but the request does not work. I have 46 documents marked with "forest" or "conservation", one of which is also marked as "asia" and none of them are marked as "uk" or "europe", but the query does not return any results.

I also saw information about the fq parameter (filtered query) for SOLR, which sounded like it might be useful. But that didn't help either. The combination of NOT and OR seems to trigger SOLR.

Am I trying to do this? Is my logic spoiled somewhere? This is on SOLR 1.4 btw - if this is a problem that has been resolved somewhere ....

Thanks for any advice!

+5
source share
1 answer

to try

 tag:((forest OR conservation) AND (africa OR asia OR (*:* AND !uk AND !europe))) 
+8
source

Source: https://habr.com/ru/post/945813/


All Articles