如何使用环绕查询解析器否定solr查询

时间:2015-07-30 15:09:15

标签: solr lucene surround booleanquery

有没有办法否定solr环绕声查询?我在fq字段中使用它,如果这给了我更多选项来否定结果。

fq={!surround}fieldName:2w(foo,bar)

我通常通过在' - '之前取消过滤器,例如,

fq=-fieldName:baz

但是当您使用环绕查询执行此操作时会出现错误:

fq=-{!surround}fieldName:2w(foo,bar)

org.apache.solr.search.SyntaxError: org.apache.lucene.queryparser.surround.parser.ParseException: Encountered "<EOF>" at line 1, column 24.
Was expecting one of:
    <OR> ...
    <AND> ...
    <NOT> ...
    <W> ...
    <N> ...
    ")" ...
    "," ...
    "^" ...

好吧,也许' - '是不被允许的,你不能有一个孤独的不。这有效:

q={!surround}AND(fieldName:2w(foo,bar),otherField:baz)

但是失败了

q={!surround}AND(NOT(fieldName:2w(foo,bar)),otherField:baz)

org.apache.solr.search.SyntaxError: org.apache.lucene.queryparser.surround.parser.ParseException: Encountered " <NOT> "NOT "" at line 1, column 4.
Was expecting one of:
    <OR> ...
    <AND> ...
    <W> ...
    <N> ...
    "(" ...
    <TRUNCQUOTED> ...
    <QUOTED> ...
    <SUFFIXTERM> ...
    <TRUNCTERM> ...
    <TERM> ...

2 个答案:

答案 0 :(得分:1)

如&#34所示;期待其中一个&#34; bit,Surround不支持+/-语法,但确实有NOT

NOT(fieldName:baz)

Careful of that lonely NOT, though.

答案 1 :(得分:0)

从8.2开始(并且不太可能由8.3修复),NOT的语法被错误地记录为“一元”,实际上是二进制的,并且需要一个前项,因此喜欢

foo NOT bar

使用foo而不是bar查找事物,因此您的查询将是

{!surround}fieldName:2w(foo,bar) NOT (otherField:baz)

似乎没有必要为该字段加上最后的括号。我确实测试过Solr将接受此查询。我没有方便的数据来验证它是否能完全提供您希望的结果。