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 "M.S. Buiter" <M....@amc.uva.nl> on 2009/01/14 16:14:10 UTC
How to get XML response from CommonsHttpSolrServer through
QueryResponse?
Dear All,
Until now we have used Solr from a servlet in which we built the
solr URL, and used response.sendRedirect(url) to send the query to
solr, and have it translate its XML results, through XSLT, to HTML.
We now want to do the XML/XSL translation process ourselves,
and to accomplish that I no longer redirect my servlet to the solr
url, but use a CommonsHttpSolrServlet to which I pass the parameters
using ModifiableSolrParams:
CommonsHttpSolrServer server = new CommonsHttpSolrServer("http://localhost:8080/kannada/db");
server.setParser(new XMLResponseParser());
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("q", searchTerms);
params.set("q.op", combination);
QueryResponse solrResponse = null;
try{
solrResponse = server.query(params);
} catch(Exception e) {
System.out.println("Exception occured in SOLR");
}
When I so a System.out(solrResponse), I get:
{responseHeader={status=0,QTime=141,params={q=library,q.op=AND,wt=xml,version=2.2}},response={numFound=180,start=0,docs=[SolrDocument[{timestamp=Wed Jan 07 16:36:51 CET 2009, sum (...)
Because I used server.setParser(new XMLResponseParser()), I get the wt=xml parameter
in the responseHeader, but the format of the responseHeader is clearly no XML at all. I expect
Solr does output XML, but that the QueryResponse, when I print its contents, formats this as the
string above.
Is there any way to directly obtain Solr's XML output?
Kind regards, and many thanks in advance,
Maarten Buiter
Re: How to get XML response from CommonsHttpSolrServer through
QueryResponse?
Posted by Chris Hostetter <ho...@fucit.org>.
: Because I used server.setParser(new XMLResponseParser()), I get the
: wt=xml parameter in the responseHeader, but the format of the
: responseHeader is clearly no XML at all. I expect Solr does output XML,
: but that the QueryResponse, when I print its contents, formats this as
: the string above.
what you are seeing is the results of the toString message on the
QueryResponse object generated by the parser -- the XML is gone at this
point, the XMLResponseParser processed it to generate that object.
that's really the main value add of using the SolrServer/ResponseParser
APIs ... if you want the raw XML response there's almost no value in using
those classes at all -- just use the HttpClient directly.
-Hoss