org.apache.solr.client.solrj.request.QueryRequest类的使用及代码示例

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

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

QueryRequest介绍

暂无

代码示例

代码示例来源:origin: apache/metron

public QueryRequest getListCollectionsRequest() {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set(SolrConstants.REQUEST_ACTION, CollectionParams.CollectionAction.LIST.name());
  QueryRequest request = new QueryRequest(params);
  request.setPath(SolrConstants.REQUEST_COLLECTIONS_PATH);
  return request;
 }
}

代码示例来源:origin: apache/nifi

private String getFieldNameOfUniqueKey() {
  final SolrQuery solrQuery = new SolrQuery();
  try {
    solrQuery.setRequestHandler("/schema/uniquekey");
    final QueryRequest req = new QueryRequest(solrQuery);
    if (isBasicAuthEnabled()) {
      req.setBasicAuthCredentials(getUsername(), getPassword());
    }
    return(req.process(getSolrClient()).getResponse().get("uniqueKey").toString());
  } catch (SolrServerException | IOException e) {
    getLogger().error("Solr query to retrieve uniqueKey-field failed due to {}", new Object[]{solrQuery.toString(), e}, e);
    throw new ProcessException(e);
  }
}

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

public void open() throws IOException {
 if (cache != null) {
  cloudSolrClient = cache.getCloudSolrClient(zkHost);
 } else {
  final List<String> hosts = new ArrayList<>();
  hosts.add(zkHost);
  cloudSolrClient = new Builder(hosts, Optional.empty()).build();
 }
 String json = getJsonFacetString(field, metrics, start, end, gap);
 ModifiableSolrParams paramsLoc = new ModifiableSolrParams(params);
 paramsLoc.set("json.facet", json);
 paramsLoc.set("rows", "0");
 QueryRequest request = new QueryRequest(paramsLoc);
 try {
  NamedList response = cloudSolrClient.request(request, collection);
  getTuples(response, field, metrics);
 } catch (Exception e) {
  throw new IOException(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;
}

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

public NamedList<Double> call() throws Exception {
  ModifiableSolrParams params = new ModifiableSolrParams();
  HttpSolrClient solrClient = cache.getHttpSolrClient(baseUrl);
  params.add(DISTRIB, "false");
  params.add("fq","{!igain}");
  for(String key : paramsMap.keySet()) {
   params.add(key, paramsMap.get(key));
  }
  params.add("outcome", outcome);
  params.add("positiveLabel", Integer.toString(positiveLabel));
  params.add("field", field);
  params.add("numTerms", String.valueOf(numTerms));
  QueryRequest request= new QueryRequest(params);
  QueryResponse response = request.process(solrClient);
  NamedList res = response.getResponse();
  return res;
 }
}

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

public void open() throws IOException {
 ModifiableSolrParams paramsLoc = new ModifiableSolrParams(this.params);
 addStats(paramsLoc, metrics);
 paramsLoc.set("stats", "true");
 paramsLoc.set("rows", "0");
  QueryRequest request = new QueryRequest(paramsLoc);
  CloudSolrClient cloudSolrClient = cache.getCloudSolrClient(zkHost);
  try {
  QueryRequest request = new QueryRequest(paramsLoc);
  try {
   NamedList response = client.request(request);

代码示例来源: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: org.apache.solr/solr-solrj

ModifiableSolrParams params = new ModifiableSolrParams();
params.add(CommonParams.QT, "/terms");
params.add(TermsParams.TERMS, "true");
params.add(TermsParams.TERMS_FIELD, field);
params.add(TermsParams.TERMS_STATS, "true");
params.add(DISTRIB, "true");
QueryRequest request = new QueryRequest(params);

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

public void open() throws IOException {
 cloudSolrClient = cache.getCloudSolrClient(zkHost);
 ModifiableSolrParams params = getParams(this.props);
 StringBuilder builder = new StringBuilder();
 for(String key : mltParams) {
  if(params.get(key) != null) {
   builder.append(" " + key + "=" + params.get(key));
   params.remove(key);
  }
 }
 String k = params.get("k");
 if(k != null) {
  params.add(ROWS, k);
  params.remove(k);
 }
 params.add(Q, "{!mlt"+builder.toString()+"}"+id);
 QueryRequest request = new QueryRequest(params);
 try {
  QueryResponse response = request.process(cloudSolrClient, collection);
  SolrDocumentList docs = response.getResults();
  documentIterator = docs.iterator();
 } catch (Exception e) {
  throw new IOException(e);
 }
}

代码示例来源: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: org.apache.solr/solr-solrj

/**
 * Performs a query to the Solr server
 *
 * @param collection the Solr collection to query
 * @param params  an object holding all key/value parameters to send along the request
 *
 * @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
 */
public QueryResponse query(String collection, SolrParams params) throws SolrServerException, IOException {
 return new QueryRequest(params).process(this, collection);
}

代码示例来源: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: org.dspace.dependencies.solr/dspace-solr-core

params.remove(CommonParams.WT); // use default (currently javabin)
params.remove(CommonParams.VERSION);
QueryRequest req = new QueryRequest(params);
req.setMethod(SolrRequest.METHOD.POST);

代码示例来源: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.beam/beam-sdks-java-io-solr

QueryResponse query(String collection, SolrParams solrParams)
  throws IOException, SolrServerException {
 QueryRequest query = new QueryRequest(solrParams);
 return process(collection, query);
}

代码示例来源: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.pageseeder.flint/pso-flint-solr

public QueryResponse request(QueryRequest request) {
 try {
  return request.process(this._client, this._collection);
 } catch (SolrServerException | IOException ex) {
  LOGGER.error("Failed to run query request {}", request, ex);
 }
 return null;
}

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

protected CollectionAdminResponse createCollection(Map<String, List<Integer>> collectionInfos, String collectionName, Map<String, Object> collectionProps, SolrClient client, String confSetName)  throws SolrServerException, IOException{
 ModifiableSolrParams params = new ModifiableSolrParams();
 params.set("action", CollectionAction.CREATE.toString());
 for (Map.Entry<String, Object> entry : collectionProps.entrySet()) {
  if(entry.getValue() !=null) params.set(entry.getKey(), String.valueOf(entry.getValue()));
  params.set(DocCollection.STATE_FORMAT, "1");
 SolrRequest request = new QueryRequest(params);
 request.setPath("/admin/collections");

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

public NamedList<Double> call() throws Exception {
  ModifiableSolrParams params = new ModifiableSolrParams();
  HttpSolrClient solrClient = cache.getHttpSolrClient(baseUrl);
  params.add(DISTRIB, "false");
  params.add("fq","{!significantTerms}");
  for(String key : paramsMap.keySet()) {
   params.add(key, paramsMap.get(key));
  }
  params.add("minDocFreq", Float.toString(minDocFreq));
  params.add("maxDocFreq", Float.toString(maxDocFreq));
  params.add("minTermLength", Integer.toString(minTermLength));
  params.add("field", field);
  params.add("numTerms", String.valueOf(numTerms*5));
  QueryRequest request= new QueryRequest(params);
  QueryResponse response = request.process(solrClient);
  NamedList res = response.getResponse();
  return res;
 }
}

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

public void open() throws IOException {
 if(cache != null) {
  cloudSolrClient = cache.getCloudSolrClient(zkHost);
 } else {
  final List<String> hosts = new ArrayList<>();
  hosts.add(zkHost);
  cloudSolrClient = new CloudSolrClient.Builder(hosts, Optional.empty()).build();
 }
 ModifiableSolrParams params = getParams(this.props);
 params.remove(SORT); //Override any sort.
 Random rand = new Random();
 int seed = rand.nextInt();
 String sortField = "random_"+seed;
 params.add(SORT, sortField+" asc");
 QueryRequest request = new QueryRequest(params);
 try {
  QueryResponse response = request.process(cloudSolrClient, collection);
  SolrDocumentList docs = response.getResults();
  documentIterator = docs.iterator();
 } catch (Exception e) {
  throw new IOException(e);
 }
}

相关文章