You also do the full query with one level of BooleanQuery by using the BooleanQuery#setMinimumNumberShouldMatch(int min) method. The default minimum number of optional clauses to match is zero, but you can set it to 1 for your case. I don't know if there is any difference in performance or scoring between these two approaches.

Using Solr, it's the "mm" request parameter.

-- Jack Krupansky

-----Original Message----- From: neosky
Sent: Tuesday, October 09, 2012 12:43 AM
To: solr-user@lucene.apache.org
Subject: How to use complicated boolean query?

I want to implement a query in Solr like the follow
((X OR Y) AND Z) … ((X ∨ Y) ∧ Z)
BooleanQuery q = new BooleanQuery();
BooleanQuery inner = new BooleanQuery();
inner.add(X, Occur.SHOULD);
inner.add(Y, Occur.SHOULD);
q.add(inner, Occur.MUST);
q.add(Z, Occur.MUST);

For example, I want to query
(Field1=X or Field1=Y ) and Field2=Z

Thanks!



--
View this message in context: http://lucene.472066.n3.nabble.com/How-to-use-complicated-boolean-query-tp4012649.html Sent from the Solr - User mailing list archive at Nabble.com.

Reply via email to