added the JSON response writer to solr interface, add &wt=json to the

servlet GET properties to use this format
pull/1/head
Michael Peter Christen 12 years ago
parent 3276508d1b
commit 70b10e8316

@ -14,6 +14,7 @@ import net.yacy.search.solr.SolrServlet;
import org.apache.solr.common.util.FastWriter;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.JSONResponseWriter;
import org.apache.solr.response.QueryResponseWriter;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.response.XMLResponseWriter;
@ -24,7 +25,8 @@ import de.anomic.server.serverSwitch;
public class select {
private static SolrServlet solrServlet = new SolrServlet();
private static final QueryResponseWriter responseWriter = new XMLResponseWriter();
private static final QueryResponseWriter xmlResponseWriter = new XMLResponseWriter();
private static final QueryResponseWriter jsonResponseWriter = new JSONResponseWriter();
static {
try {solrServlet.init(null);} catch (ServletException e) {}
@ -55,6 +57,8 @@ public class select {
if (connector == null) return null;
if (post == null) return null;
if (!post.containsKey("df")) post.put("df", "text_t"); // set default field to all fields
QueryResponseWriter responseWriter = xmlResponseWriter;
if (post.get("wt", "").equals("json")) responseWriter = jsonResponseWriter;
SolrQueryRequest req = connector.request(post.toSolrParams());
SolrQueryResponse response = connector.query(req);
Exception e = response.getException();

Loading…
Cancel
Save