org.apache.solr.client.solrj.request.QueryRequest.setResponseParser()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(73)

本文整理了Java中org.apache.solr.client.solrj.request.QueryRequest.setResponseParser方法的一些代码示例,展示了QueryRequest.setResponseParser的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QueryRequest.setResponseParser方法的具体详情如下:
包路径:org.apache.solr.client.solrj.request.QueryRequest
类名称:QueryRequest
方法名:setResponseParser

QueryRequest.setResponseParser介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

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 );

代码示例来源:origin: org.apache.solr/solr-solrj

/**
 * 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);
}

代码示例来源:origin: com.hynnet/solr-solrj

/**
 * 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);
}

代码示例来源:origin: org.apache.solr/solr-solrj

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);
}

代码示例来源:origin: com.hynnet/solr-solrj

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);
}

代码示例来源:origin: com.sitewhere/sitewhere-solr

@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);
}
}

代码示例来源:origin: org.apache.solr/solr-solrj

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);
  }
 }
}

代码示例来源:origin: sitewhere/sitewhere

@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);
}
}

代码示例来源:origin: org.apache.solr/solr-test-framework

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;
}

相关文章