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 Ashwin Tandel <as...@gmail.com> on 2013/06/24 20:37:34 UTC

Creating solr query.

Hi,

It's with regards to generating a query string for Solr.
I am looking for a solution where I can create the query string like

'q=name:ipod AND cat=music AND features=cool&facet=on&facet.field=cat'

Is there any library through which we can create this query string.

I came across Solrj but looks like it is not as reach as lucene API.

Is there a way we can use lucene API and generate the query string or is
there any other way.

Thanks in Advance,

Ashwin

Re: Creating solr query.

Posted by Jack Krupansky <ja...@basetechnology.com>.
>From the SolrJWiki:
http://wiki.apache.org/solr/Solrj#Advanced_usage

SolrServer server = getSolrServer();
  SolrQuery solrQuery = new  SolrQuery().
                setQuery("ipod").
                setFacet(true).
                setFacetMinCount(1).
                setFacetLimit(8).
                addFacetField("category").
                addFacetField("inStock");
  QueryResponse rsp = server.query(solrQuery);

The setQuery method takes the query string itself, like:

                setQuery("name:ipod AND cat:music AND features:cool").

Note that your example tries to facet on the "cat" field, but the query 
restricts results to the single category "music".

-- Jack Krupansky

-----Original Message----- 
From: Ashwin Tandel
Sent: Monday, June 24, 2013 2:37 PM
To: solr-user
Subject: Creating solr query.

Hi,

It's with regards to generating a query string for Solr.
I am looking for a solution where I can create the query string like

'q=name:ipod AND cat=music AND features=cool&facet=on&facet.field=cat'

Is there any library through which we can create this query string.

I came across Solrj but looks like it is not as reach as lucene API.

Is there a way we can use lucene API and generate the query string or is
there any other way.

Thanks in Advance,

Ashwin 


Re: Creating solr query.

Posted by Gora Mohanty <go...@mimirtech.com>.
On 25 June 2013 00:07, Ashwin Tandel <as...@gmail.com> wrote:
> Hi,
>
> It's with regards to generating a query string for Solr.
> I am looking for a solution where I can create the query string like
>
> 'q=name:ipod AND cat=music AND features=cool&facet=on&facet.field=cat'

> Is there any library through which we can create this query string.
>
> I came across Solrj but looks like it is not as reach as lucene API.

Your query above does not seem to be Lucene specific, and
can well be handled by Solr. This might be a good starting point:
http://wiki.apache.org/solr/SolrQuerySyntax

> Is there a way we can use lucene API and generate the query string or is
> there any other way.

As Erik replied in the earlier thread, if you really need Lucene syntax
your best bet would be to write a custom QParser.

Regards,
Gora