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 Jon Poulton <Jo...@vyre.com> on 2010/01/07 18:25:38 UTC

SolJ and query parameters

Hi there,
I'm trying to understand how the query syntax specified on the Solr Wiki ( http://wiki.apache.org/solr/SolrQuerySyntax ) fits in with the usage of the SolJ class SolrQuery. There are not too many examples of usage to be found.

For example. Say I wanted to replicate the following query using SolrQuery.

q={!lucene q.op=AND df=text}myfield:foo +bar -baz

How would I do it so that q.op was set to "OR" instead of "AND"? There is no method I can see on SolrQuery to set q.op, only a "query string", which is presumably in this case is the text "+bar -baz", as the rest can be specified by calling set methods on SolrQuery.

Thanks in advance for any help.

Jon



Re: SolJ and query parameters

Posted by Ryan McKinley <ry...@gmail.com>.
On Jan 7, 2010, at 1:05 PM, Jon Poulton wrote:

> I've also just noticed that QueryParsing is not in the SolrJ API.  
> It's in one of the other Solr jar dependencies.
>
> I'm beginning to think that maybe the best approach it to write a  
> query string generator which can generate strings of the form:
>
> q={!lucene q.op=AND df=text}myfield:foo +bar -baz
>
> Then just set this on a SolrQuery instance and send it over the  
> wire. It not the kind of string you'd want an end user to have to  
> type out.
>

Yes, if you need to manipulate the local params, that seems like a  
good approach.

Solrj was written before the local params syntax was introduced.

A patch that adds LocalParams support to solrj would be welcome :)

ryan



RE: SolJ and query parameters

Posted by Jon Poulton <Jo...@vyre.com>.
I've also just noticed that QueryParsing is not in the SolrJ API. It's in one of the other Solr jar dependencies.

I'm beginning to think that maybe the best approach it to write a query string generator which can generate strings of the form: 

q={!lucene q.op=AND df=text}myfield:foo +bar -baz

Then just set this on a SolrQuery instance and send it over the wire. It not the kind of string you'd want an end user to have to type out.

-----Original Message-----
From: Ahmet Arslan [mailto:iorixxx@yahoo.com] 
Sent: 07 January 2010 17:38
To: solr-user@lucene.apache.org
Subject: Re: SolJ and query parameters



--- On Thu, 1/7/10, Jon Poulton <Jo...@vyre.com> wrote:

> From: Jon Poulton <Jo...@vyre.com>
> Subject: SolJ and query parameters
> To: "'solr-user@lucene.apache.org'" <so...@lucene.apache.org>
> Date: Thursday, January 7, 2010, 7:25 PM
> Hi there,
> I'm trying to understand how the query syntax specified on
> the Solr Wiki ( http://wiki.apache.org/solr/SolrQuerySyntax ) fits in
> with the usage of the SolJ class SolrQuery. There are not
> too many examples of usage to be found.
> 
> For example. Say I wanted to replicate the following query
> using SolrQuery.
> 
> q={!lucene q.op=AND df=text}myfield:foo +bar -baz

Whole string is the value of the parameter q.

SolrQuery.setQuery("{!lucene q.op=AND df=text}myfield:foo +bar -baz");

> How would I do it so that q.op was set to "OR" instead of
> "AND"? There is no method I can see on SolrQuery to set
> q.op, only a "query string", which is presumably in this
> case is the text "+bar -baz", as the rest can be specified
> by calling set methods on SolrQuery.

if you want to set q.op to AND you can use SolrQuery.set(QueryParsing.OP,"AND");

hope this helps.


      

RE: SolJ and query parameters

Posted by Ahmet Arslan <io...@yahoo.com>.
> Using SolrQuery.setQuery("{!lucene q.op=AND
> df=text}myfield:foo +bar -baz}"); would make more sense if
> it were not for the other methods available on SolrQuery. 
> 
> For example, there is a "setFields(String..)" method. So
> what happens if I call setFields("title", "description")
> after having set the query to the above value? What do I end
> up with? Something like this:
>
> {!lucene q.op=AND df=text}title:(foo +bar -baz)
> description:(foo +bar baz)}

No. setFields is equvalent to  &fl=title,description  It determines which fields will be returned as a result.

> I'm still having trouble understanding how the class is
> intended to be used. 

SolrQuery extends ModifiableSolrParams. If you look at the source code of it you can understand. For example setQuery method invokes this.set(CommonParams.Q, query);

You can set anything in the search url with this class. &key=value is equal to SolrQuery.set(key, value). There are some multivalued keys like fq and facet.field, in those cases you can use add() method.


      

RE: SolJ and query parameters

Posted by Jon Poulton <Jo...@vyre.com>.
Thanks for the reply. 

Using SolrQuery.setQuery("{!lucene q.op=AND df=text}myfield:foo +bar -baz}"); would make more sense if it were not for the other methods available on SolrQuery. 

For example, there is a "setFields(String..)" method. So what happens if I call setFields("title", "description") after having set the query to the above value? What do I end up with? Something like this:

{!lucene q.op=AND df=text}title:(foo +bar -baz) description:(foo +bar baz)}

I'm still having trouble understanding how the class is intended to be used. 

Cheers

Jon


-----Original Message-----
From: Ahmet Arslan [mailto:iorixxx@yahoo.com] 
Sent: 07 January 2010 17:38
To: solr-user@lucene.apache.org
Subject: Re: SolJ and query parameters



--- On Thu, 1/7/10, Jon Poulton <Jo...@vyre.com> wrote:

> From: Jon Poulton <Jo...@vyre.com>
> Subject: SolJ and query parameters
> To: "'solr-user@lucene.apache.org'" <so...@lucene.apache.org>
> Date: Thursday, January 7, 2010, 7:25 PM
> Hi there,
> I'm trying to understand how the query syntax specified on
> the Solr Wiki ( http://wiki.apache.org/solr/SolrQuerySyntax ) fits in
> with the usage of the SolJ class SolrQuery. There are not
> too many examples of usage to be found.
> 
> For example. Say I wanted to replicate the following query
> using SolrQuery.
> 
> q={!lucene q.op=AND df=text}myfield:foo +bar -baz

Whole string is the value of the parameter q.

SolrQuery.setQuery("{!lucene q.op=AND df=text}myfield:foo +bar -baz");

> How would I do it so that q.op was set to "OR" instead of
> "AND"? There is no method I can see on SolrQuery to set
> q.op, only a "query string", which is presumably in this
> case is the text "+bar -baz", as the rest can be specified
> by calling set methods on SolrQuery.

if you want to set q.op to AND you can use SolrQuery.set(QueryParsing.OP,"AND");

hope this helps.


      

Re: SolJ and query parameters

Posted by Ahmet Arslan <io...@yahoo.com>.

--- On Thu, 1/7/10, Jon Poulton <Jo...@vyre.com> wrote:

> From: Jon Poulton <Jo...@vyre.com>
> Subject: SolJ and query parameters
> To: "'solr-user@lucene.apache.org'" <so...@lucene.apache.org>
> Date: Thursday, January 7, 2010, 7:25 PM
> Hi there,
> I'm trying to understand how the query syntax specified on
> the Solr Wiki ( http://wiki.apache.org/solr/SolrQuerySyntax ) fits in
> with the usage of the SolJ class SolrQuery. There are not
> too many examples of usage to be found.
> 
> For example. Say I wanted to replicate the following query
> using SolrQuery.
> 
> q={!lucene q.op=AND df=text}myfield:foo +bar -baz

Whole string is the value of the parameter q.

SolrQuery.setQuery("{!lucene q.op=AND df=text}myfield:foo +bar -baz");

> How would I do it so that q.op was set to "OR" instead of
> "AND"? There is no method I can see on SolrQuery to set
> q.op, only a "query string", which is presumably in this
> case is the text "+bar -baz", as the rest can be specified
> by calling set methods on SolrQuery.

if you want to set q.op to AND you can use SolrQuery.set(QueryParsing.OP,"AND");

hope this helps.