【问题标题】:Lucene QueryParser issueLucene QueryParser 问题
【发布时间】:2012-06-22 11:22:12
【问题描述】:

有人可以解释为什么原始查询(以编程方式生成)中的 OR(左起第二个)在解析后的查询中变为 MUST 吗?如何防止这种情况发生?

Original Query: +matchAllDocs:true +( request_id:(00000000000000000000000000002796 OR 00000000000000000000000000002829) OR ( matchAllDocs:true AND ( request_id:(00000000000000000000000000002796) AND status_id:(1)) OR ( request_id:(00000000000000000000000000002829) AND status_id:(2))) AND (alltext:(internal) OR subject:(internal )^1.5))

Parsed Query: +matchAllDocs:true +((request_id:00000000000000000000000000002796 request_id:00000000000000000000000000002829) +(+matchAllDocs:true +(+request_id:00000000000000000000000000002796 +status_id:1) (+request_id:00000000000000000000000000002829 +status_id:2)) +(alltext:intern subject:intern^1.5))

谢谢

【问题讨论】:

    标签: lucene query-parser


    【解决方案1】:

    因为 AND 击败 OR(运算顺序):

    (something) OR //left will be SHOULD
    (
        matchAllDocs:true AND 
        (
            request_id:(00000000000000000000000000002796) AND status_id:(1)
        ) OR 
        (
             request_id:(00000000000000000000000000002829) AND status_id:(2)
        )
    ) **AND** // left will be MUST
    (alltext:(internal) OR subject:(internal )^1.5)
    

    解决方案是使用更多的括号,如下所示:

    +matchAllDocs:true +((request_id:(00000000000000000000000000002796 OR 00000000000000000000000000002829) OR ( matchAllDocs:true AND ( request_id:(00000000000000000000000000002796) AND status_id:(1)) OR ( request_id:(00000000000000000000000000002829) AND status_id:(2)))) AND (alltext:(internal) OR subject:(internal )^1.5))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-20
      • 2013-02-20
      • 2014-08-07
      • 2011-08-28
      • 1970-01-01
      相关资源
      最近更新 更多