11

对于 Solr 中的过滤器查询,我需要包含所有非特定类型的文档,以及在特定字段中具有值的该类型的任何文档。

我试过这个:

fq=(-type_id:(A) OR content:(['' TO *]))

但它不包括type_id具有 null 的 B、C 等文档content。(type_id是一个string字段并且contenttext.)

我看过这个问题:Complex SOLR query including NOT and OR和这篇关于运算符的帖子:http ://robotlibrarian.billdueber.com/2011/12/solr-and-boolean-operators/ 。我认为我的语法应该是正确的。谁能看到我的错误?


更新:我正在使用 LuceneQParser。它将上面的过滤查询解析为

-type_id:A content:['' TO *]

-type_id:A OR (content:[* TO *] AND type_id:A)它将评论 ( ) 中建议的过滤器查询解析为

-type_id:A (+content:[* TO *] +type_id:A)

所以没有结果。

4

1 回答 1

18

否定需要一个完整的集合来匹配它,所以你的过滤器应该是:

fq=((*:* AND -type_id:A) OR content:(['' TO *]))
于 2015-01-29T17:47:33.677 回答