Java Code Examples for org.apache.solr.client.solrj.request.QueryRequest#setResponseParser()
The following examples show how to use
org.apache.solr.client.solrj.request.QueryRequest#setResponseParser() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSONTupleStream.java From lucene-solr with Apache License 2.0 | 6 votes |
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, StandardCharsets.UTF_8); return new JSONTupleStream(reader); }
Example 2
Source File: SolrClient.java From lucene-solr with Apache License 2.0 | 5 votes |
private QueryResponse getQueryResponse(String collection, SolrParams params, ResponseParser parser) throws SolrServerException, IOException { QueryRequest req = new QueryRequest(params); if (parser instanceof StreamingBinaryResponseParser) { req.setStreamingResponseCallback(((StreamingBinaryResponseParser) parser).callback); } req.setResponseParser(parser); return req.process(this, collection); }
Example 3
Source File: SolrStream.java From lucene-solr with Apache License 2.0 | 5 votes |
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); if(user != null && password != null) { query.setBasicAuthCredentials(user, password); } 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, StandardCharsets.UTF_8); return new JSONTupleStream(reader); } }
Example 4
Source File: AnalyticsShardRequestManager.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Send the analytics request to the shard. */ @Override public SolrException call() throws Exception { client = new HttpSolrClient.Builder(baseUrl).build(); QueryRequest query = new QueryRequest( params ); query.setPath(AnalyticsHandler.NAME); query.setResponseParser(new AnalyticsShardResponseParser(manager)); query.setMethod(SolrRequest.METHOD.POST); NamedList<Object> exception = client.request(query); if (exception.size() > 0) { return (SolrException)exception.getVal(0); } return null; }
Example 5
Source File: ShowFileRequestHandlerTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testGetRawFile() throws SolrServerException, IOException { SolrClient client = getSolrClient(); //assertQ(req("qt", "/admin/file")); TODO file bug that SolrJettyTestBase extends SolrTestCaseJ4 QueryRequest request = new QueryRequest(params("file", "managed-schema")); request.setPath("/admin/file"); final AtomicBoolean readFile = new AtomicBoolean(); request.setResponseParser(new ResponseParser() { @Override public String getWriterType() { return "mock";//unfortunately this gets put onto params wt=mock but it apparently has no effect } @Override public NamedList<Object> processResponse(InputStream body, String encoding) { try { if (body.read() >= 0) readFile.set(true); } catch (IOException e) { throw new RuntimeException(e); } return null; } @Override public NamedList<Object> processResponse(Reader reader) { throw new UnsupportedOperationException("TODO unimplemented");//TODO } }); client.request(request);//runs request //request.process(client); but we don't have a NamedList response assertTrue(readFile.get()); }
Example 6
Source File: DistributedTermsComponentTest.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Returns a {@link NamedList} containing server * response deserialization is based on the {@code responseParser} */ private NamedList<Object> queryClient(SolrClient solrClient, final ModifiableSolrParams params, ResponseParser responseParser) throws SolrServerException, IOException { QueryRequest queryRequest = new QueryRequest(params); queryRequest.setResponseParser(responseParser); return solrClient.request(queryRequest); }
Example 7
Source File: GraphExpressionTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void testGraphHandler() throws Exception { new UpdateRequest() .add(id, "0", "from_s", "bill", "to_s", "jim", "message_t", "Hello jim") .add(id, "1", "from_s", "bill", "to_s", "sam", "message_t", "Hello sam") .add(id, "2", "from_s", "bill", "to_s", "max", "message_t", "Hello max") .add(id, "3", "from_s", "max", "to_s", "kip", "message_t", "Hello kip") .add(id, "4", "from_s", "sam", "to_s", "steve", "message_t", "Hello steve") .add(id, "5", "from_s", "jim", "to_s", "ann", "message_t", "Hello steve") .commit(cluster.getSolrClient(), COLLECTION); commit(); List<JettySolrRunner> runners = cluster.getJettySolrRunners(); JettySolrRunner runner = runners.get(0); String url = runner.getBaseUrl().toString(); HttpSolrClient client = getHttpSolrClient(url); ModifiableSolrParams params = new ModifiableSolrParams(); String expr = "sort(by=\"node asc\", gatherNodes(collection1, " + "walk=\"bill->from_s\"," + "trackTraversal=\"true\"," + "gather=\"to_s\"))"; params.add("expr", expr); QueryRequest query = new QueryRequest(params); query.setPath("/collection1/graph"); query.setResponseParser(new InputStreamResponseParser("xml")); query.setMethod(SolrRequest.METHOD.POST); NamedList<Object> genericResponse = client.request(query); InputStream stream = (InputStream)genericResponse.get("stream"); InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8); String xml = readString(reader); //Validate the nodes String error = BaseTestHarness.validateXPath(xml, "//graph/node[1][@id ='jim']", "//graph/node[2][@id ='max']", "//graph/node[3][@id ='sam']"); if(error != null) { throw new Exception(error); } //Validate the edges error = BaseTestHarness.validateXPath(xml, "//graph/edge[1][@source ='bill']", "//graph/edge[1][@target ='jim']", "//graph/edge[2][@source ='bill']", "//graph/edge[2][@target ='max']", "//graph/edge[3][@source ='bill']", "//graph/edge[3][@target ='sam']"); if(error != null) { throw new Exception(error); } client.close(); }