2

It looks like the QueryResponse from Solrj has no mean to give you a quoted Json string with wt=on or not. All I received is something like this

{responseHeader={status=0,QTime=2,params= {fl=id,productName,imageFront,priceEng,priceEngExp...

Question:

1) Am I missing something here ? Or there is no way to get the json response properly from the Solr server by Solrj.

2) Now on my client, if I convert the non-quoted json string from Solrj, does it mean it was done two times, once in server time and one in the Solrj client time ?

Tommy Lord
  • 543
  • 1
  • 7
  • 13

2 Answers2

9

You can get JSON response by setting wt=json to the Solr query. Example URL is shown below :

localhost:8983/solr/select/?q=:&rows=10&indent=on&wt=json

You can't get JSON response using Solrj. You don't need to use Solrj for this purpose.By sending HTTP requests to the URL above, you can get json response.

Parvin Gasimzade
  • 25,180
  • 8
  • 56
  • 83
  • found out Soljr only does javabin and xml. I cant expose my search server to the users. That is why I needed some intermediate webserver in between. Finally, had to stream response from the search server to client with some kind of connection pooling for better performance. Thank you for your suggestion though – Tommy Lord Jul 24 '12 at 09:01
2

With newer versions of Solr (starting with 4.7.0) it is possible to return the query response directly in json-format. This can be done with the NoOpResponseParser.

SolrQuery query = new SolrQuery();
QueryRequest req = new QueryRequest(query);

NoOpResponseParser rawJsonResponseParser = new NoOpResponseParser();
rawJsonResponseParser.setWriterType("json");
req.setResponseParser(rawJsonResponseParser);

NamedList<Object> resp = mySolrClient.request(req);
String jsonResponse = (String) resp.get("response");

System.out.println(jsonResponse );