My java code searches value using solr.But it gives the output in xml or jason format.I want My output as a single value so that i can store it in haspmap.Can anyone show me an example?Thanks in adavance.
Asked
Active
Viewed 1,648 times
0
-
1Can you show some efforts from your side as well ? we would be happy to help. – Jayendra Jul 04 '13 at 06:05
3 Answers
0
You can use Google Gson to make it to object or array, then store it into the hashmap with an unique based on the document id, guid...
Here is the user guide to Gson

Dan Le
- 308
- 2
- 10
0
You can use the JSON or GSON to convert the output into an object and then parse the object into any data structure you wish.
If you are an advanced user then you can get the results in JAVABIN FORMAT which is fast.

John
- 281
- 3
- 14
0
This is by using SolrJ API we can achieve what you need .
import java.util.Map;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
public class NewSolrResponse {
/**
* @param args
*/
public static void main(String[] args) {
HttpSolrServer solrServer = new HttpSolrServer("http://youtHost:port/Solr"); //set your URL where your index data pointing to
SolrQuery query = new SolrQuery(" ") ; // set your query String ;
try {
QueryResponse queryResponse = solrServer.query(query);
SolrDocumentList solrDocumentList = queryResponse.getResults();
for (SolrDocument solrDocument : solrDocumentList) {
Map<String, Object> yourParamMap = solrDocument.getFieldValueMap(); /// Here you will get Fields and their Values
}
} catch (SolrServerException e) {
e.printStackTrace();
}
}
}

Suryaprakash Pisay
- 642
- 8
- 23