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 );
/** * Query solr, and stream the results. Unlike the standard query, this will * send events for each Document rather then add them to the QueryResponse. * * Although this function returns a 'QueryResponse' it should be used with care * since it excludes anything that was passed to callback. Also note that * future version may pass even more info to the callback and may not return * the results in the QueryResponse. * * @param collection the Solr collection to query * @param params an object holding all key/value parameters to send along the request * @param callback the callback to stream results to * * @return a {@link org.apache.solr.client.solrj.response.QueryResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server * * @since solr 5.1 */ public QueryResponse queryAndStreamResponse(String collection, SolrParams params, StreamingResponseCallback callback) throws SolrServerException, IOException { ResponseParser parser = new StreamingBinaryResponseParser(callback); QueryRequest req = new QueryRequest(params); req.setStreamingResponseCallback(callback); req.setResponseParser(parser); return req.process(this, collection); }
/** * Query solr, and stream the results. Unlike the standard query, this will * send events for each Document rather then add them to the QueryResponse. * * Although this function returns a 'QueryResponse' it should be used with care * since it excludes anything that was passed to callback. Also note that * future version may pass even more info to the callback and may not return * the results in the QueryResponse. * * @param collection the Solr collection to query * @param params an object holding all key/value parameters to send along the request * @param callback the callback to stream results to * * @return a {@link org.apache.solr.client.solrj.response.QueryResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server * * @since solr 5.1 */ public QueryResponse queryAndStreamResponse(String collection, SolrParams params, StreamingResponseCallback callback) throws SolrServerException, IOException { ResponseParser parser = new StreamingBinaryResponseParser(callback); QueryRequest req = new QueryRequest(params); req.setStreamingResponseCallback(callback); req.setResponseParser(parser); return req.process(this, collection); }
public static JSONTupleStream create(SolrClient server, SolrParams requestParams) throws IOException, SolrServerException { String p = requestParams.get("qt"); if(p != null) { ModifiableSolrParams modifiableSolrParams = (ModifiableSolrParams) requestParams; modifiableSolrParams.remove("qt"); } QueryRequest query = new QueryRequest( requestParams ); query.setPath(p); query.setResponseParser(new InputStreamResponseParser("json")); query.setMethod(SolrRequest.METHOD.POST); NamedList<Object> genericResponse = server.request(query); InputStream stream = (InputStream)genericResponse.get("stream"); InputStreamReader reader = new InputStreamReader(stream, "UTF-8"); return new JSONTupleStream(reader); }
public static JSONTupleStream create(SolrClient server, SolrParams requestParams) throws IOException, SolrServerException { String p = requestParams.get("qt"); if(p != null) { ModifiableSolrParams modifiableSolrParams = (ModifiableSolrParams) requestParams; modifiableSolrParams.remove("qt"); } QueryRequest query = new QueryRequest( requestParams ); query.setPath(p); query.setResponseParser(new InputStreamResponseParser("json")); query.setMethod(SolrRequest.METHOD.POST); NamedList<Object> genericResponse = server.request(query); InputStream stream = (InputStream)genericResponse.get("stream"); InputStreamReader reader = new InputStreamReader(stream, "UTF-8"); return new JSONTupleStream(reader); }
@Override public JsonNode executeQueryWithRawResponse(String queryString) throws SiteWhereException { try { LOGGER.debug("About to execute Solr search with query string: " + queryString); NoOpResponseParser rawJsonResponseParser = new NoOpResponseParser(); rawJsonResponseParser.setWriterType("json"); SolrQuery query = new SolrQuery(); query.add(createParamsFromQueryString(queryString)); QueryRequest request = new QueryRequest(query); request.setResponseParser(rawJsonResponseParser); NamedList<?> results = getSolr().getSolrClient().request(request); return MAPPER.readTree((String) results.get("response")); } catch (SolrServerException e) { throw new SiteWhereException("Unable to execute query.", e); } catch (IOException e) { throw new SiteWhereException("Unable to execute query.", e); } }
public TupleStreamParser constructParser(SolrClient server, SolrParams requestParams) throws IOException, SolrServerException { String p = requestParams.get("qt"); if (p != null) { ModifiableSolrParams modifiableSolrParams = (ModifiableSolrParams) requestParams; modifiableSolrParams.remove("qt"); //performance optimization - remove extra whitespace by default when streaming modifiableSolrParams.set("indent", modifiableSolrParams.get("indent", "off")); } String wt = requestParams.get(CommonParams.WT, "json"); QueryRequest query = new QueryRequest(requestParams); query.setPath(p); query.setResponseParser(new InputStreamResponseParser(wt)); query.setMethod(SolrRequest.METHOD.POST); NamedList<Object> genericResponse = server.request(query); InputStream stream = (InputStream) genericResponse.get("stream"); this.closeableHttpResponse = (CloseableHttpResponse)genericResponse.get("closeableResponse"); if (CommonParams.JAVABIN.equals(wt)) { return new JavabinTupleStreamParser(stream, true); } else { InputStreamReader reader = new InputStreamReader(stream, "UTF-8"); return new JSONTupleStream(reader); } } }
@Override public JsonNode executeQueryWithRawResponse(String queryString) throws SiteWhereException { try { getLogger().debug("About to execute Solr search with query string: " + queryString); NoOpResponseParser rawJsonResponseParser = new NoOpResponseParser(); rawJsonResponseParser.setWriterType("json"); SolrQuery query = new SolrQuery(); query.add(createParamsFromQueryString(queryString)); QueryRequest request = new QueryRequest(query); request.setResponseParser(rawJsonResponseParser); NamedList<?> results = getSolrConnection().getSolrClient().request(request); return MAPPER.readTree((String) results.get("response")); } catch (SolrServerException e) { throw new SiteWhereException("Unable to execute query.", e); } catch (IOException e) { throw new SiteWhereException("Unable to execute query.", e); } }
public static String getQueryResponse(SolrClient client, String wt, SolrParams params) throws Exception { if (client == null) { return getQueryResponse(wt, params); } ModifiableSolrParams p = new ModifiableSolrParams(params); p.set("wt", wt); String path = p.get("qt"); p.remove("qt"); p.set("indent","true"); QueryRequest query = new QueryRequest( p ); if (path != null) { query.setPath(path); } query.setResponseParser(new NoOpResponseParser(wt)); NamedList<Object> rsp = client.request(query); String raw = (String)rsp.get("response"); return raw; }