You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by neosky <ne...@yahoo.com> on 2012/10/09 06:43:56 UTC
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.
Re: How to use complicated boolean query?
Posted by Alexandre Rafalovitch <ar...@gmail.com>.
And the problem is? I think it is just brackets. E.g.
Field1:(X Y) AND Field2:Z
No?
On 9 Oct 2012 10:14, "neosky" <ne...@yahoo.com> wrote:
> 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.
>
Re: How to use complicated boolean query?
Posted by Jack Krupansky <ja...@basetechnology.com>.
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.