Java Code Examples for org.apache.solr.client.solrj.request.QueryRequest#setMethod()

The following examples show how to use org.apache.solr.client.solrj.request.QueryRequest#setMethod() . 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 vote down vote up
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: SolrStream.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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 3
Source File: AnalyticsShardRequestManager.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * 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 4
Source File: IterativeMergeStrategy.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public CallBack(ShardResponse originalShardResponse, QueryRequest req) {

      this.solrClient = new Builder(originalShardResponse.getShardAddress())
          .withHttpClient(httpClient)
          .build();
      this.req = req;
      this.originalShardResponse = originalShardResponse;
      req.setMethod(SolrRequest.METHOD.POST);
      ModifiableSolrParams params = (ModifiableSolrParams)req.getParams();
      params.add(DISTRIB, "false");
    }
 
Example 5
Source File: AbstractAlfrescoDistributedIT.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected static QueryRequest getAlfrescoRequest(String json, SolrParams params) {
    QueryRequest request = new AlfrescoJsonQueryRequest(json, params);
    request.setMethod(SolrRequest.METHOD.POST);
    return request;
}
 
Example 6
Source File: GraphExpressionTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example 7
Source File: ShardRequestor.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public ShardResponse call() throws Exception {

  ShardResponse srsp = new ShardResponse();
  if (sreq.nodeName != null) {
    srsp.setNodeName(sreq.nodeName);
  }
  srsp.setShardRequest(sreq);
  srsp.setShard(shard);
  SimpleSolrResponse ssr = new SimpleSolrResponse();
  srsp.setSolrResponse(ssr);
  long startTime = System.nanoTime();

  try {
    params.remove(CommonParams.WT); // use default (currently javabin)
    params.remove(CommonParams.VERSION);

    QueryRequest req = httpShardHandler.makeQueryRequest(sreq, params, shard);
    if (tracer != null && span != null) {
      tracer.inject(span.context(), Format.Builtin.HTTP_HEADERS, new SolrRequestCarrier(req));
    }
    req.setMethod(SolrRequest.METHOD.POST);
    SolrRequestInfo requestInfo = SolrRequestInfo.getRequestInfo();
    if (requestInfo != null) req.setUserPrincipal(requestInfo.getReq().getUserPrincipal());

    // no need to set the response parser as binary is the defaultJab
    // req.setResponseParser(new BinaryResponseParser());

    // if there are no shards available for a slice, urls.size()==0
    if (urls.size() == 0) {
      // TODO: what's the right error code here? We should use the same thing when
      // all of the servers for a shard are down.
      throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "no servers hosting shard: " + shard);
    }

    if (urls.size() <= 1) {
      String url = urls.get(0);
      srsp.setShardAddress(url);
      ssr.nl = httpShardHandler.request(url, req);
    } else {
      LBSolrClient.Rsp rsp = httpShardHandler.httpShardHandlerFactory.makeLoadBalancedRequest(req, urls);
      ssr.nl = rsp.getResponse();
      srsp.setShardAddress(rsp.getServer());
    }
  } catch (ConnectException cex) {
    srsp.setException(cex); //????
  } catch (Exception th) {
    srsp.setException(th);
    if (th instanceof SolrException) {
      srsp.setResponseCode(((SolrException) th).code());
    } else {
      srsp.setResponseCode(-1);
    }
  }

  ssr.elapsedTime = TimeUnit.MILLISECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS);

  return httpShardHandler.transfomResponse(sreq, srsp, shard);
}