You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-dev@lucene.apache.org by Otis Gospodnetic <ot...@yahoo.com> on 2007/02/16 21:26:53 UTC

RequestHandler -> XML/JSON/etc. response?

Hi,



I'm still torturing SOLR-81 - the spellchecker fronted with a Solr RequestHandler.

Being a RequestHandler virgin, I'm not sure how to go from getting the alternative

spelling suggestion(s) in the RequestHandler, to the output that might look something

like this (made it up on the spot, please point out any weaknesses):



<?xml version="1.0" encoding="UTF-8"?>

<response>

<responseHeader>Is the response header really needed?</responseHeader>



<result numSuggestions="N">

 <suggestion>suggestion 1</suggestion>

 ...

 <suggestion>suggestion N</suggestion>

</result>

</response>



I'm looking at StandardRequestHandler, trying to base y RequestHandler on it, but I don't see where the results get XML-ified.
I see  rsp.add("response",results.docList);  and friends, but it's not clear to me at this crazy hour at night how that makes it to the XMLWriter or XMLResponseWriter, or some other class that finally spits out XML.

Can somebody please point me in the right direction?

Thanks,

Otis






Re: RequestHandler -> XML/JSON/etc. response?

Posted by Chris Hostetter <ho...@fucit.org>.
: Are spelling suggestions going to be a separate request to Solr or
: would it all be within the desired request handler output, such that
: they could be incorporated into DisMax or Standard request handler
: output?

i think Otis is tackling hte use case where the Solr index models a
dictionary -- each doc is a single "word" with fields containing various
ngrams of that word, and other properties about how/why it might be a good
suggestion.


-Hoss


Re: RequestHandler -> XML/JSON/etc. response?

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Feb 16, 2007, at 4:28 PM, Ryan McKinley wrote:

> On 2/16/07, Erik Hatcher <er...@ehatchersolutions.com> wrote:
>>
>> from SolrDispatchFilter, we have this:
>>
>>            QueryResponseWriter responseWriter =
>> core.getQueryResponseWriter(solrReq);
>>            response.setContentType(responseWriter.getContentType
>> (solrReq, solrRsp));
>>            PrintWriter out = response.getWriter();
>>            responseWriter.write(out, solrReq, solrRsp);
>>
>>
>> This is how the output gets written as XML (or Ruby in my case,
>> &wt=ruby :).
>>
>
> But the SolrRequestHandler author does not need to worry about pushing
> the output into various formats - that all happens automatically.

Right... I was just giving Otis some details on how the magic happened.

	Erik




Re: RequestHandler -> XML/JSON/etc. response?

Posted by Ryan McKinley <ry...@gmail.com>.
On 2/16/07, Erik Hatcher <er...@ehatchersolutions.com> wrote:
>
> from SolrDispatchFilter, we have this:
>
>            QueryResponseWriter responseWriter =
> core.getQueryResponseWriter(solrReq);
>            response.setContentType(responseWriter.getContentType
> (solrReq, solrRsp));
>            PrintWriter out = response.getWriter();
>            responseWriter.write(out, solrReq, solrRsp);
>
>
> This is how the output gets written as XML (or Ruby in my case,
> &wt=ruby :).
>

But the SolrRequestHandler author does not need to worry about pushing
the output into various formats - that all happens automatically.  You
just need to dump results into the SolrQueryResponse and they will be
written out appropriately.

The values you can put in (without extending all the ResponseWriters) are:
 * Collection
 * Object[]
  * Document (lucene)
 * Map
 * standard types (int/float/string) etc
  * everything else gets added as object.toString()

Re: RequestHandler -> XML/JSON/etc. response?

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Feb 16, 2007, at 3:26 PM, Otis Gospodnetic wrote:
> I'm still torturing SOLR-81 - the spellchecker fronted with a Solr  
> RequestHandler.
>
> Being a RequestHandler virgin, I'm not sure how to go from getting  
> the alternative
>
> spelling suggestion(s) in the RequestHandler, to the output that  
> might look something
>
> like this (made it up on the spot, please point out any weaknesses):
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <response>
>
> <responseHeader>Is the response header really needed?</responseHeader>
>
>
>
> <result numSuggestions="N">
>
>  <suggestion>suggestion 1</suggestion>
>
>  ...
>
>  <suggestion>suggestion N</suggestion>
>
> </result>
>
> </response>
>
>
>
> I'm looking at StandardRequestHandler, trying to base y  
> RequestHandler on it, but I don't see where the results get XML-ified.
> I see  rsp.add("response",results.docList);  and friends, but it's  
> not clear to me at this crazy hour at night how that makes it to  
> the XMLWriter or XMLResponseWriter, or some other class that  
> finally spits out XML.
>
> Can somebody please point me in the right direction?

from SolrDispatchFilter, we have this:

           QueryResponseWriter responseWriter =  
core.getQueryResponseWriter(solrReq);
           response.setContentType(responseWriter.getContentType 
(solrReq, solrRsp));
           PrintWriter out = response.getWriter();
           responseWriter.write(out, solrReq, solrRsp);


This is how the output gets written as XML (or Ruby in my case,  
&wt=ruby :).

Are spelling suggestions going to be a separate request to Solr or  
would it all be within the desired request handler output, such that  
they could be incorporated into DisMax or Standard request handler  
output?

	Erik


Re: RequestHandler -> XML/JSON/etc. response?

Posted by Ryan McKinley <ry...@gmail.com>.
why not just the standard list format so we don't have to write new parsers :)

   List<String> suggestions = new ArrayList<String>();
    suggestions.add( "suggestion 1" );
    suggestions.add( "suggestion 2" );
    suggestions.add( "suggestion 3" );
    suggestions.add( "suggestion 4" );
    rsp.add( "suggestions", suggestions );

gives:

<arr name="suggestions">
 <str>suggestion 1</str>
 <str>suggestion 2</str>
 <str>suggestion 3</str>
 <str>suggestion 4</str>
</arr>

or:

"suggestions":[
  "suggestion 1",
  "suggestion 2",
  "suggestion 3",
  "suggestion 4"],

we can get the numSuggestions from the array length

ryan



On 2/16/07, Otis Gospodnetic <ot...@yahoo.com> wrote:
> Hi,
>
>
>
> I'm still torturing SOLR-81 - the spellchecker fronted with a Solr RequestHandler.
>
> Being a RequestHandler virgin, I'm not sure how to go from getting the alternative
>
> spelling suggestion(s) in the RequestHandler, to the output that might look something
>
> like this (made it up on the spot, please point out any weaknesses):
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <response>
>
> <responseHeader>Is the response header really needed?</responseHeader>
>
>
>
> <result numSuggestions="N">
>
>  <suggestion>suggestion 1</suggestion>
>
>  ...
>
>  <suggestion>suggestion N</suggestion>
>
> </result>
>
> </response>
>
>
>
> I'm looking at StandardRequestHandler, trying to base y RequestHandler on it, but I don't see where the results get XML-ified.
> I see  rsp.add("response",results.docList);  and friends, but it's not clear to me at this crazy hour at night how that makes it to the XMLWriter or XMLResponseWriter, or some other class that finally spits out XML.
>
> Can somebody please point me in the right direction?
>
> Thanks,
>
> Otis
>
>
>
>
>
>