Lucene QueryParser问题

时间:2012-06-20 10:26:28

标签: lucene query-parser

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

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

由于

1 个答案:

答案 0 :(得分:0)

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