Can We append a field to the response that is not in the index but computed at runtime.

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Can We append a field to the response that is not in the index but computed at runtime.

Umar Shah
Hi,

I wanted to know whether we can append a field (Fdyn say) to each doc in the
returned set
Fdyn is computed as some complex function of the fields stored in the index
during the runtime in SOLR.



-umar
Reply | Threaded
Open this post in threaded view
|

Re: Can We append a field to the response that is not in the index but computed at runtime.

Ryan McKinley
Without writing any custom code, no.

If you write a "SearchComponent" http://wiki.apache.org/solr/SearchComponent 
  -- you can programatically change the response at runtime.

ryan



On Mar 28, 2008, at 3:38 AM, Umar Shah wrote:

> Hi,
>
> I wanted to know whether we can append a field (Fdyn say) to each  
> doc in the
> returned set
> Fdyn is computed as some complex function of the fields stored in  
> the index
> during the runtime in SOLR.
>
>
>
> -umar

Reply | Threaded
Open this post in threaded view
|

Re: Can We append a field to the response that is not in the index but computed at runtime.

Umar Shah
thanks ryan for the reply.

I have looked at the prepare and process methods in SearchComponents(Query,
Filter etc).
I'm using all the default components to prepare and then process the reults.
and then prepare a custom field after iterating through all the documents in
the result set. After having created this field for each document how do I
add corresponding custom field to each document in the response set.


On Mon, Mar 31, 2008 at 6:25 PM, Ryan McKinley <[hidden email]> wrote:

> Without writing any custom code, no.
>
> If you write a "SearchComponent"
> http://wiki.apache.org/solr/SearchComponent
>  -- you can programatically change the response at runtime.
>
> ryan
>
>
>
> On Mar 28, 2008, at 3:38 AM, Umar Shah wrote:
>
> > Hi,
> >
> > I wanted to know whether we can append a field (Fdyn say) to each
> > doc in the
> > returned set
> > Fdyn is computed as some complex function of the fields stored in
> > the index
> > during the runtime in SOLR.
> >
> >
> >
> > -umar
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Can We append a field to the response that is not in the index but computed at runtime.

Ryan McKinley
Two approaches:
1. make a map and add it to the response:
   rb.rsp.add( "mystuff", mymap );

2. Augment the documents with a field value -- this is a bit more  
complex and runs the risk of name collisions with fields in your  
documents.  You can pull the docLIst out from the response and add  
fields to each document.

If #1 works, go with that...

ryan



On Mar 31, 2008, at 9:51 AM, Umar Shah wrote:

> thanks ryan for the reply.
>
> I have looked at the prepare and process methods in  
> SearchComponents(Query,
> Filter etc).
> I'm using all the default components to prepare and then process the  
> reults.
> and then prepare a custom field after iterating through all the  
> documents in
> the result set. After having created this field for each document  
> how do I
> add corresponding custom field to each document in the response set.
>
>
> On Mon, Mar 31, 2008 at 6:25 PM, Ryan McKinley <[hidden email]>  
> wrote:
>
>> Without writing any custom code, no.
>>
>> If you write a "SearchComponent"
>> http://wiki.apache.org/solr/SearchComponent
>> -- you can programatically change the response at runtime.
>>
>> ryan
>>
>>
>>
>> On Mar 28, 2008, at 3:38 AM, Umar Shah wrote:
>>
>>> Hi,
>>>
>>> I wanted to know whether we can append a field (Fdyn say) to each
>>> doc in the
>>> returned set
>>> Fdyn is computed as some complex function of the fields stored in
>>> the index
>>> during the runtime in SOLR.
>>>
>>>
>>>
>>> -umar
>>
>>

Reply | Threaded
Open this post in threaded view
|

Re: Can We append a field to the response that is not in the index but computed at runtime.

Umar Shah
On Mon, Mar 31, 2008 at 7:38 PM, Ryan McKinley <[hidden email]> wrote:

> Two approaches:
> 1. make a map and add it to the response:
>   rb.rsp.add( "mystuff", mymap );
>

I tried using both  Map/ NamedList

it appends to the results
I have to attach each document with corresponding field.


> 2. Augment the documents with a field value -- this is a bit more
> complex and runs the risk of name collisions with fields in your
> documents.  You can pull the docLIst out from the response and add
> fields to each document.

this seems more appropriate,
I'm okay, to resolve name collision , how do I add the  field.. any specific
methods to do that?


> If #1 works, go with that...
>
> ryan
>
>
>
> On Mar 31, 2008, at 9:51 AM, Umar Shah wrote:
>
> > thanks ryan for the reply.
> >
> > I have looked at the prepare and process methods in
> > SearchComponents(Query,
> > Filter etc).
> > I'm using all the default components to prepare and then process the
> > reults.
> > and then prepare a custom field after iterating through all the
> > documents in
> > the result set. After having created this field for each document
> > how do I
> > add corresponding custom field to each document in the response set.
> >
> >
> > On Mon, Mar 31, 2008 at 6:25 PM, Ryan McKinley <[hidden email]>
> > wrote:
> >
> >> Without writing any custom code, no.
> >>
> >> If you write a "SearchComponent"
> >> http://wiki.apache.org/solr/SearchComponent
> >> -- you can programatically change the response at runtime.
> >>
> >> ryan
> >>
> >>
> >>
> >> On Mar 28, 2008, at 3:38 AM, Umar Shah wrote:
> >>
> >>> Hi,
> >>>
> >>> I wanted to know whether we can append a field (Fdyn say) to each
> >>> doc in the
> >>> returned set
> >>> Fdyn is computed as some complex function of the fields stored in
> >>> the index
> >>> during the runtime in SOLR.
> >>>
> >>>
> >>>
> >>> -umar
> >>
> >>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Can We append a field to the response that is not in the index but computed at runtime.

Siegfried Goeschl
Hi folks,

I had to solve a similiar problem with SOLR 1.2 and used a custom
org.apache.solr.request.QueryResponseWriter - you can trigger your
custom response writer using SOLR admin but it is not an elegant
solution (I think the XMWriter is a final class therefore some
copy&waste code)

Cheers,

Siegfried Goeschl



Umar Shah wrote:

> On Mon, Mar 31, 2008 at 7:38 PM, Ryan McKinley <[hidden email]> wrote:
>
>  
>> Two approaches:
>> 1. make a map and add it to the response:
>>   rb.rsp.add( "mystuff", mymap );
>>
>>    
>
> I tried using both  Map/ NamedList
>
> it appends to the results
> I have to attach each document with corresponding field.
>
>
>  
>> 2. Augment the documents with a field value -- this is a bit more
>> complex and runs the risk of name collisions with fields in your
>> documents.  You can pull the docLIst out from the response and add
>> fields to each document.
>>    
>
> this seems more appropriate,
> I'm okay, to resolve name collision , how do I add the  field.. any specific
> methods to do that?
>
>
>  
>> If #1 works, go with that...
>>
>> ryan
>>
>>
>>
>> On Mar 31, 2008, at 9:51 AM, Umar Shah wrote:
>>
>>    
>>> thanks ryan for the reply.
>>>
>>> I have looked at the prepare and process methods in
>>> SearchComponents(Query,
>>> Filter etc).
>>> I'm using all the default components to prepare and then process the
>>> reults.
>>> and then prepare a custom field after iterating through all the
>>> documents in
>>> the result set. After having created this field for each document
>>> how do I
>>> add corresponding custom field to each document in the response set.
>>>
>>>
>>> On Mon, Mar 31, 2008 at 6:25 PM, Ryan McKinley <[hidden email]>
>>> wrote:
>>>
>>>      
>>>> Without writing any custom code, no.
>>>>
>>>> If you write a "SearchComponent"
>>>> http://wiki.apache.org/solr/SearchComponent
>>>> -- you can programatically change the response at runtime.
>>>>
>>>> ryan
>>>>
>>>>
>>>>
>>>> On Mar 28, 2008, at 3:38 AM, Umar Shah wrote:
>>>>
>>>>        
>>>>> Hi,
>>>>>
>>>>> I wanted to know whether we can append a field (Fdyn say) to each
>>>>> doc in the
>>>>> returned set
>>>>> Fdyn is computed as some complex function of the fields stored in
>>>>> the index
>>>>> during the runtime in SOLR.
>>>>>
>>>>>
>>>>>
>>>>> -umar
>>>>>          
>>>>        
>>    
>
>  
Reply | Threaded
Open this post in threaded view
|

Re: Can We append a field to the response that is not in the index but computed at runtime.

hossman
In reply to this post by Umar Shah

: > 2. Augment the documents with a field value -- this is a bit more
: > complex and runs the risk of name collisions with fields in your
: > documents.  You can pull the docLIst out from the response and add
: > fields to each document.
:
: this seems more appropriate,
: I'm okay, to resolve name collision , how do I add the  field.. any specific
: methods to do that?

I *think* the missing step here is that while DocLists can't easily be
modified, new SolrDocument and SolrDocumentList classes have been
added since 1.2.  Solr by defualt doesn't use them, but the built in Solr
ResponseWriters can output them, so your custom component can build a
SolrDocumentList bsed on the DocList, and add whatever fields you want.

I'm not sure if there are any help methods to do the
DocList->SolrDocumentList conversion.

(Ryan: keep my honest if this isn't what you had in mind)




-Hoss

Reply | Threaded
Open this post in threaded view
|

Re: Can We append a field to the response that is not in the index but computed at runtime.

Ryan McKinley

On Mar 31, 2008, at 2:43 PM, Chris Hostetter wrote:

>
> : > 2. Augment the documents with a field value -- this is a bit more
> : > complex and runs the risk of name collisions with fields in your
> : > documents.  You can pull the docLIst out from the response and add
> : > fields to each document.
> :
> : this seems more appropriate,
> : I'm okay, to resolve name collision , how do I add the  field..  
> any specific
> : methods to do that?
>
> I *think* the missing step here is that while DocLists can't easily be
> modified, new SolrDocument and SolrDocumentList classes have been
> added since 1.2.  Solr by defualt doesn't use them, but the built in  
> Solr
> ResponseWriters can output them, so your custom component can build a
> SolrDocumentList bsed on the DocList, and add whatever fields you  
> want.
>
> I'm not sure if there are any help methods to do the
> DocList->SolrDocumentList conversion.
>
> (Ryan: keep my honest if this isn't what you had in mind)
>

Correct -- there isn't really a clean way to do this.

For an example, you can check the "locallucene" query component:
https://locallucene.svn.sourceforge.net/svnroot/locallucene/trunk/localsolr/src/com/pjaol/search/solr/component/LocalSolrQueryComponent.java
(towards the bottom of process)

that adds a calculated "geo_distance" field to each returned document.

ryan








>
>
>
> -Hoss
>

Reply | Threaded
Open this post in threaded view
|

Re: Can We append a field to the response that is not in the index but computed at runtime.

Umar Shah
In reply to this post by hossman
thanks ryan

seems like this would be helpful.
will try it out.

thanks again.
-umar


On Tue, Apr 1, 2008 at 12:13 AM, Chris Hostetter <[hidden email]>
wrote:

>
> : > 2. Augment the documents with a field value -- this is a bit more
> : > complex and runs the risk of name collisions with fields in your
> : > documents.  You can pull the docLIst out from the response and add
> : > fields to each document.
> :
> : this seems more appropriate,
> : I'm okay, to resolve name collision , how do I add the  field.. any
> specific
> : methods to do that?
>
> I *think* the missing step here is that while DocLists can't easily be
> modified, new SolrDocument and SolrDocumentList classes have been
> added since 1.2.  Solr by defualt doesn't use them, but the built in Solr
> ResponseWriters can output them, so your custom component can build a
> SolrDocumentList bsed on the DocList, and add whatever fields you want.
>
> I'm not sure if there are any help methods to do the
> DocList->SolrDocumentList conversion.
>
> (Ryan: keep my honest if this isn't what you had in mind)
>
>
>
>
> -Hoss
>
>