You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Zaccheo Bagnati <za...@gmail.com> on 2016/03/23 18:56:51 UTC

retrieve Query in DocumentTransformer

Hi all,
I'm trying to develop a custom DocumentTransformer in SOLR but I'm not able
to retrieve the Query object when the request is executed with group=true.
Let me explain more in detail:
the purpose of this Transformer is to apply highlight on a field, extract
some information from the highlighted field and set those information in
the result.
To use Highlighter I need the Query. I can obtain it using
context.getQuery() in the implementation of transform() method and this is
working BUTunfortunately, when the request contains some grouping
parameters (group=true&group.field=...), getQuery() returns a null pointer.
I ended up in re-parsing the query with
QParser.getParser(context.getRequest().getParams().get("q"),...)
but I wonder if there is a better way.
I'm pretty new in SOLR developing so maybe I'm missing something obvious...
Thank you in advance.

Re: retrieve Query in DocumentTransformer

Posted by Zaccheo Bagnati <za...@gmail.com>.
Yes, it is exactly what I'm using. But it seems to work only if there isn't
a group parameter in the request, otherwise getQuery() is returning null
pointer. Do you think it is a bug?

Il giorno mer 23 mar 2016 alle ore 20:09 Ryan McKinley <ry...@gmail.com>
ha scritto:

> Can you use the ResultContext#getQuery()?
>
> https://github.com/apache/lucene-solr/blob/master/solr/core/src/java/org/apache/solr/response/ResultContext.java#L42
>
> This will get passed to you from:
> DockTransformer#setContext()
>
> https://github.com/apache/lucene-solr/blob/master/solr/core/src/java/org/apache/solr/response/transform/DocTransformer.java#L48
>
> ryan
>
>
> On Wed, Mar 23, 2016 at 10:56 AM, Zaccheo Bagnati <za...@gmail.com>
> wrote:
>
>> Hi all,
>> I'm trying to develop a custom DocumentTransformer in SOLR but I'm not
>> able to retrieve the Query object when the request is executed with
>> group=true.
>> Let me explain more in detail:
>> the purpose of this Transformer is to apply highlight on a field, extract
>> some information from the highlighted field and set those information in
>> the result.
>> To use Highlighter I need the Query. I can obtain it using
>> context.getQuery() in the implementation of transform() method and this is
>> working BUTunfortunately, when the request contains some grouping
>> parameters (group=true&group.field=...), getQuery() returns a null pointer.
>> I ended up in re-parsing the query with
>> QParser.getParser(context.getRequest().getParams().get("q"),...)
>> but I wonder if there is a better way.
>> I'm pretty new in SOLR developing so maybe I'm missing something
>> obvious...
>> Thank you in advance.
>>
>
>

Re: retrieve Query in DocumentTransformer

Posted by Ryan McKinley <ry...@gmail.com>.
Can you use the ResultContext#getQuery()?
https://github.com/apache/lucene-solr/blob/master/solr/core/src/java/org/apache/solr/response/ResultContext.java#L42

This will get passed to you from:
DockTransformer#setContext()
https://github.com/apache/lucene-solr/blob/master/solr/core/src/java/org/apache/solr/response/transform/DocTransformer.java#L48

ryan


On Wed, Mar 23, 2016 at 10:56 AM, Zaccheo Bagnati <za...@gmail.com>
wrote:

> Hi all,
> I'm trying to develop a custom DocumentTransformer in SOLR but I'm not
> able to retrieve the Query object when the request is executed with
> group=true.
> Let me explain more in detail:
> the purpose of this Transformer is to apply highlight on a field, extract
> some information from the highlighted field and set those information in
> the result.
> To use Highlighter I need the Query. I can obtain it using
> context.getQuery() in the implementation of transform() method and this is
> working BUTunfortunately, when the request contains some grouping
> parameters (group=true&group.field=...), getQuery() returns a null pointer.
> I ended up in re-parsing the query with
> QParser.getParser(context.getRequest().getParams().get("q"),...)
> but I wonder if there is a better way.
> I'm pretty new in SOLR developing so maybe I'm missing something obvious...
> Thank you in advance.
>