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 Marc SCHNEIDER <ma...@gmail.com> on 2011/06/03 09:15:02 UTC

Getting query fields in a custom SearchHandler

Hi all,

I wrote my own SearchHandler and therefore overrided the handleRequestBody
method.
This method takes two input parameters : SolrQueryRequest and
SolrQueryResponse objects.
The thing I'd like to do is to get the query fields that are used in my
request.
Of course I can use req.getParams().get("q") but it returns the complete
query (which can be very complicated). I'd like to have a simple map with
field:value.
Is there a way to get it? Or do I have to write my own parser for the "q"
parameter?

Thanks in advance,
Marc.

Re: Getting query fields in a custom SearchHandler

Posted by Marc SCHNEIDER <ma...@gmail.com>.
Hi,

I reply to myself :-)
The solution is to use this utility class :
org.apache.solr.search.QueryParsing. Then you can do:

Query luceneQuery = QueryParsing.parseQuery(req.getParams().get("q"),
req.getSchema());

Then with luceneQuery you can use the extractTerms method.

Marc.

On Fri, Jun 3, 2011 at 9:15 AM, Marc SCHNEIDER
<ma...@gmail.com>wrote:

> Hi all,
>
> I wrote my own SearchHandler and therefore overrided the handleRequestBody
> method.
> This method takes two input parameters : SolrQueryRequest and
> SolrQueryResponse objects.
> The thing I'd like to do is to get the query fields that are used in my
> request.
> Of course I can use req.getParams().get("q") but it returns the complete
> query (which can be very complicated). I'd like to have a simple map with
> field:value.
> Is there a way to get it? Or do I have to write my own parser for the "q"
> parameter?
>
> Thanks in advance,
> Marc.
>