Complex SOLR query including NOT and OR

自闭症网瘾萝莉.ら 提交于 2019-12-10 15:04:11

问题


I have some fairly complex requirements for a SOLR search that I need to execute against my database of tagged content. I need to first filter the database to those results matching my filter tags. Any of these results which have a tag from the blacklist should be removed unless they also contain tags from the whitelist.

So let's say I want to retrieve all documents tagged "forest" or "conservation". But I want to exclude documents tagged "uk" or "europe" - unless they are also tagged with "africa" or "asia". I tried to write this in my SOLR query:

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

The logic seems sound to me but the query doesn't work. I have 46 documents tagged with "forest" or "conservation" - one of which is also tagged with "asia" and none of which are tagged with "uk" or "europe" but the query returns no results.

I also saw information about the fq (filtered query) parameter to SOLR which sounded like it could be useful. But this didn't seem to help either. It seems it is the combination of NOT and OR which causes SOLR to break down.

Is what I'm trying to do possible? Is my logic flawed somewhere? This is on SOLR 1.4 btw - incase this is an issue which has been resolved somewhere....

Thanks for any advice!


回答1:


try

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


来源:https://stackoverflow.com/questions/10688910/complex-solr-query-including-not-and-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!