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 Steven White <sw...@gmail.com> on 2019/07/09 22:52:15 UTC

SolrQuery setting the boolean operator to use

Hi everyone,

In this code sample that's part of my overall code, how do I tell Solr
dynamically / programmatically to use AND or OR as the default operator?

SolrQuery query = new SolrQuery(queryString);
query.setRequestHandler("/select_test");

response = solrClient.query(query);
SolrDocumentList documents = response.getResults();
long count = documents.getNumFound();

Thanks

Steven

Re: SolrQuery setting the boolean operator to use

Posted by Steven White <sw...@gmail.com>.
Thanks Shawn!  That was quick, easy and it works.

Steven

On Tue, Jul 9, 2019 at 6:57 PM Shawn Heisey <ap...@elyograg.org> wrote:

> On 7/9/2019 4:52 PM, Steven White wrote:
> > In this code sample that's part of my overall code, how do I tell Solr
> > dynamically / programmatically to use AND or OR as the default operator?
> >
> > SolrQuery query = new SolrQuery(queryString);
> > query.setRequestHandler("/select_test");
> >
> > response = solrClient.query(query);
> > SolrDocumentList documents = response.getResults();
> > long count = documents.getNumFound();
>
> At the blank line in the code above, before actually executing the
> query, add something like this:
>
> query.set("q.op", "OR");
>
> This is doing the same thing as adding &q.op=OR to the URL parameters on
> a manual request.
>
> Thanks,
> Shawn
>

Re: SolrQuery setting the boolean operator to use

Posted by Shawn Heisey <ap...@elyograg.org>.
On 7/9/2019 4:52 PM, Steven White wrote:
> In this code sample that's part of my overall code, how do I tell Solr
> dynamically / programmatically to use AND or OR as the default operator?
> 
> SolrQuery query = new SolrQuery(queryString);
> query.setRequestHandler("/select_test");
> 
> response = solrClient.query(query);
> SolrDocumentList documents = response.getResults();
> long count = documents.getNumFound();

At the blank line in the code above, before actually executing the 
query, add something like this:

query.set("q.op", "OR");

This is doing the same thing as adding &q.op=OR to the URL parameters on 
a manual request.

Thanks,
Shawn