复杂的SOLR查询,包括NOT和OR [英] Complex SOLR query including NOT and OR

查看:839
本文介绍了复杂的SOLR查询,包括NOT和OR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对SOLR搜索有一些相当复杂的要求,我需要对我的加标签内容数据库执行该要求.我需要首先将数据库过滤为与我的过滤器标签匹配的结果.除非这些结果中包含黑名单中的标签,否则它们中的任何一个都应删除,除非它们还包含白名单中的标签.

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.

因此,假设我要检索所有标记为森林"或保护"的文档.但是我想排除标记为"uk"或"europe"的文档-除非它们也被标记为"africa"或"asia".我试图在我的SOLR查询中写这个:

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))

对我来说,逻辑似乎很合理,但查询不起作用.我有46个标有森林"或自然保护"的文档-其中一个也标有"asia",没有一个标有"uk"或"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.

我还看到了有关SOLR的fq(过滤查询)参数的信息,听起来像是有用的.但这似乎也无济于事.似乎是NOT和OR的组合会导致SOLR崩溃.

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.

我想做的是可能的吗?我的逻辑在某处存在缺陷吗? 这是关于SOLR 1.4 btw的情况-如果此问题已在某处得到解决....

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....

感谢您的任何建议!

推荐答案

尝试

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

这篇关于复杂的SOLR查询,包括NOT和OR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆