org.apache.solr.client.solrj.request.QueryRequest Java Examples

The following examples show how to use org.apache.solr.client.solrj.request.QueryRequest. 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: TestSuggesterResponse.java    From lucene-solr with Apache License 2.0 7 votes vote down vote up
@Test
public void testSuggesterResponseObject() throws Exception {
  getSolrClient();
  addSampleDocs();

  SolrQuery query = new SolrQuery("*:*");
  query.set(CommonParams.QT, "/suggest");
  query.set("suggest.dictionary", "mySuggester");
  query.set("suggest.q", "Com");
  query.set("suggest.build", true);
  QueryRequest request = new QueryRequest(query);
  QueryResponse queryResponse = request.process(client);
  SuggesterResponse response = queryResponse.getSuggesterResponse();
  Map<String, List<Suggestion>> dictionary2suggestions = response.getSuggestions();
  assertTrue(dictionary2suggestions.keySet().contains("mySuggester"));

  List<Suggestion> mySuggester = dictionary2suggestions.get("mySuggester");
  assertEquals("Computational framework", mySuggester.get(0).getTerm());
  assertEquals(0, mySuggester.get(0).getWeight());
  assertEquals("", mySuggester.get(0).getPayload());
  assertEquals("Computer", mySuggester.get(1).getTerm());
  assertEquals(0, mySuggester.get(1).getWeight());
  assertEquals("", mySuggester.get(1).getPayload());
}
 
Example #2
Source File: LegacyAbstractAnalyticsCloudTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected NamedList<Object> queryLegacyCloudAnalytics(String[] testParams) throws SolrServerException, IOException, InterruptedException, TimeoutException {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set("q", "*:*");
  params.set("indent", "true");
  params.set("olap", "true");
  params.set("rows", "0");
  for (int i = 0; i + 1 < testParams.length;) {
    params.add(testParams[i++], testParams[i++]);
  }
  cluster.waitForAllNodes(10000);
  QueryRequest qreq = new QueryRequest(params);
  QueryResponse resp = qreq.process(cluster.getSolrClient(), COLLECTIONORALIAS);
  final NamedList<Object> response = resp.getResponse();
  assertRequestTimeout(params);
  return response;
}
 
Example #3
Source File: TestSuggesterResponse.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptySuggesterResponse() throws Exception {
  getSolrClient();
  addSampleDocs();

  SolrQuery query = new SolrQuery("*:*");
  query.set(CommonParams.QT, "/suggest");
  query.set("suggest.dictionary", "mySuggester");
  query.set("suggest.q", "Empty");
  query.set("suggest.build", true);
  QueryRequest request = new QueryRequest(query);
  QueryResponse queryResponse = request.process(client);
  SuggesterResponse response = queryResponse.getSuggesterResponse();
  Map<String, List<String>> dictionary2suggestions = response.getSuggestedTerms();
  assertTrue(dictionary2suggestions.keySet().contains("mySuggester"));

  List<String> mySuggester = dictionary2suggestions.get("mySuggester");
  assertEquals(0, mySuggester.size());
}
 
Example #4
Source File: IndexFetcher.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"rawtypes"})
NamedList getDetails() throws IOException, SolrServerException {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set(COMMAND, CMD_DETAILS);
  params.set("slave", false);
  params.set(CommonParams.QT, ReplicationHandler.PATH);

  // TODO use shardhandler
  try (HttpSolrClient client = new HttpSolrClient.Builder(masterUrl)
      .withHttpClient(myHttpClient)
      .withConnectionTimeout(connTimeout)
      .withSocketTimeout(soTimeout)
      .build()) {
    QueryRequest request = new QueryRequest(params);
    return client.request(request);
  }
}
 
Example #5
Source File: FeaturesSelectionStream.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked"})
public NamedList<Double> call() throws Exception {
  ModifiableSolrParams params = new ModifiableSolrParams();
  HttpSolrClient solrClient = cache.getHttpSolrClient(baseUrl);

  params.add(DISTRIB, "false");
  params.add("fq","{!igain}");

  for(Map.Entry<String, String> entry : paramsMap.entrySet()) {
    params.add(entry.getKey(), entry.getValue());
  }

  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;
}
 
Example #6
Source File: TestDocLevelOperations.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
/**
 * Creates docs as follows and verifies queries work as expected:
 * - creates NUM_DOCS documents, where the document id equals the order
 *   it was created in, starting at 0
 * - even-numbered documents get "junit_role" auth token
 * - odd-numbered documents get "admin_role" auth token
 * - all documents get some bogus auth tokens
 * - all documents get a docLevel_role auth token
 */
private void createDocsAndQuerySimple(String collectionName, boolean checkNonAdminUsers) throws Exception {

  // ensure no current documents
  verifyDeletedocsPass(ADMIN_USER, collectionName, true);

  CloudSolrServer server = getCloudSolrServer(collectionName);
  try {
    DocLevelGenerator generator = new DocLevelGenerator(AUTH_FIELD);
    generator.generateDocs(server, NUM_DOCS, "junit_role", "admin_role", EXTRA_AUTH_FIELDS);

    querySimple(new QueryRequest(new SolrQuery("*:*")), server, checkNonAdminUsers);
    querySimple(getRealTimeGetRequest(), server, checkNonAdminUsers);
  } finally {
    server.shutdown();
  }
}
 
Example #7
Source File: TestDocLevelOperations.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
/**
 * delete the docs as "deleteUser" using deleteByQuery "deleteQueryStr".
 * Verify that number of docs returned for "queryUser" equals
 * "expectedQueryDocs" after deletion.
 */
private void deleteByQueryTest(String collectionName, String deleteUser,
    String deleteByQueryStr, String queryUser, int expectedQueryDocs) throws Exception {
  createDocsAndQuerySimple(collectionName, true);
  CloudSolrServer server = getCloudSolrServer(collectionName);
  try {
    setAuthenticationUser(deleteUser);
    server.deleteByQuery(deleteByQueryStr);
    server.commit();

    checkDeleteByQuery(new QueryRequest(new SolrQuery("*:*")), server,
        queryUser, expectedQueryDocs);
    checkDeleteByQuery(getRealTimeGetRequest(), server,
        queryUser, expectedQueryDocs);
  } finally {
    server.shutdown();
  }
}
 
Example #8
Source File: SolrClientInterceptorTest.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Test
public void testQuery() throws Throwable {
    QueryRequest request = new QueryRequest();
    arguments = new Object[] {
        request,
        null,
        collection
    };

    interceptor.beforeMethod(enhancedInstance, method, arguments, argumentType, null);
    interceptor.afterMethod(enhancedInstance, method, arguments, argumentType, getQueryResponse());

    List<TraceSegment> segments = segmentStorage.getTraceSegments();
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(segments.get(0));

    Assert.assertEquals(segments.size(), 1);
    Assert.assertEquals(spans.size(), 1);

    AbstractTracingSpan span = spans.get(0);
    querySpanAssert(span, "/select", 100, "solrJ/collection/select");
}
 
Example #9
Source File: SearchStream.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
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();
  }


  QueryRequest request = new QueryRequest(params, SolrRequest.METHOD.POST);
  try {
    QueryResponse response = request.process(cloudSolrClient, collection);
    SolrDocumentList docs = response.getResults();
    documentIterator = docs.iterator();
  } catch (Exception e) {
    throw new IOException(e);
  }
}
 
Example #10
Source File: TimeSeriesStream.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
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, SolrRequest.METHOD.POST);
  try {
    @SuppressWarnings({"rawtypes"})
    NamedList response = cloudSolrClient.request(request, collection);
    getTuples(response, field, metrics);
  } catch (Exception e) {
    throw new IOException(e);
  }
}
 
Example #11
Source File: TestCollectionAPI.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void clusterStatusWithCollection() throws IOException, SolrServerException {
    try (CloudSolrClient client = createCloudClient(null)) {
      ModifiableSolrParams params = new ModifiableSolrParams();
      params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
      params.set("collection", COLLECTION_NAME);
      @SuppressWarnings({"rawtypes"})
      SolrRequest request = new QueryRequest(params);
      request.setPath("/admin/collections");

      NamedList<Object> rsp = client.request(request);
      @SuppressWarnings({"unchecked"})
      NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
      assertNotNull("Cluster state should not be null", cluster);
      @SuppressWarnings({"unchecked"})
      NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
      assertNotNull("Collections should not be null in cluster state", collections);
      assertEquals(1, collections.size());
      @SuppressWarnings({"unchecked"})
      Map<String, Object> collection = (Map<String, Object>) collections.get(COLLECTION_NAME);
      assertNotNull(collection);
      assertEquals("conf1", collection.get("configName"));
//      assertEquals("1", collection.get("nrtReplicas"));
    }
  }
 
Example #12
Source File: TestCollectionAPI.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void testAliasCreationNameValidation() throws Exception{
  try (CloudSolrClient client = createCloudClient(null)) {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("action", CollectionParams.CollectionAction.CREATEALIAS.toString());
    params.set("name", "invalid@name#with$weird%characters");
    params.set("collections", COLLECTION_NAME);
    @SuppressWarnings({"rawtypes"})
    SolrRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");

    try {
      client.request(request);
      fail();
    } catch (BaseHttpSolrClient.RemoteSolrException e) {
      final String errorMessage = e.getMessage();
      assertTrue(errorMessage.contains("Invalid alias"));
      assertTrue(errorMessage.contains("invalid@name#with$weird%characters"));
      assertTrue(errorMessage.contains("alias names must consist entirely of"));
    }
  }
}
 
Example #13
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 #14
Source File: MtasSolrTestDistributedSearchConsistency.java    From mtas with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the cloud collection.
 *
 * @param collectionName
 *          the collection name
 * @param numShards
 *          the num shards
 * @param replicationFactor
 *          the replication factor
 * @param confDir
 *          the conf dir
 * @throws Exception
 *           the exception
 */
private static void createCloudCollection(String collectionName,
    int numShards, int replicationFactor, Path confDir) throws Exception {
  CloudSolrClient client = cloudCluster.getSolrClient();
  String confName = collectionName + "Configuration";
  if (confDir != null) {
    SolrZkClient zkClient = client.getZkStateReader().getZkClient();
    ZkConfigManager zkConfigManager = new ZkConfigManager(zkClient);
    zkConfigManager.uploadConfigDir(confDir, confName);
  }
  ModifiableSolrParams modParams = new ModifiableSolrParams();
  modParams.set(CoreAdminParams.ACTION,
      CollectionParams.CollectionAction.CREATE.name());
  modParams.set("name", collectionName);
  modParams.set("numShards", numShards);
  modParams.set("replicationFactor", replicationFactor);
  int liveNodes = client.getZkStateReader().getClusterState().getLiveNodes()
      .size();
  int maxShardsPerNode = (int) Math
      .ceil(((double) numShards * replicationFactor) / liveNodes);
  modParams.set("maxShardsPerNode", maxShardsPerNode);
  modParams.set("collection.configName", confName);
  QueryRequest request = new QueryRequest(modParams);
  request.setPath("/admin/collections");
  client.request(request);
}
 
Example #15
Source File: TestCloudJSONFacetSKGEquiv.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * returns the <b>FIRST</b> NamedList (under the implicit 'null' FacetQuery) in the "facet-trace" output 
 * of the request.  Should not be used with multiple "top level" facets 
 * (the output is too confusing in cloud mode to be confident where/qhy each NamedList comes from)
 */
private NamedList<Object> getFacetDebug(final SolrParams params) {
  try {
    final QueryResponse rsp = (new QueryRequest(params)).process(getRandClient(random()));
    assertNotNull(params + " is null rsp?", rsp);
    @SuppressWarnings({"rawtypes"})
    final NamedList topNamedList = rsp.getResponse();
    assertNotNull(params + " is null topNamedList?", topNamedList);
    
    // skip past the (implicit) top Facet query to get it's "sub-facets" (the real facets)...
    @SuppressWarnings({"unchecked"})
    final List<NamedList<Object>> facetDebug =
      (List<NamedList<Object>>) topNamedList.findRecursive("debug", "facet-trace", "sub-facet");
    assertNotNull(topNamedList + " ... null facet debug?", facetDebug);
    assertFalse(topNamedList + " ... not even one facet debug?", facetDebug.isEmpty());
    return facetDebug.get(0);
  } catch (Exception e) {
    throw new RuntimeException("query failed: " + params + ": " + 
                               e.getMessage(), e);
  } 

}
 
Example #16
Source File: TestCloudJSONFacetSKGEquiv.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**     
 * We ignore {@link QueryResponse#getJsonFacetingResponse()} because it isn't as useful for
 * doing a "deep equals" comparison across requests
 */
@SuppressWarnings({"rawtypes"})
private NamedList getFacetResponse(final SolrParams params) {
  try {
    final QueryResponse rsp = (new QueryRequest(params)).process(getRandClient(random()));
    assertNotNull(params + " is null rsp?", rsp);
    final NamedList topNamedList = rsp.getResponse();
    assertNotNull(params + " is null topNamedList?", topNamedList);
    final NamedList facetResponse = (NamedList) topNamedList.get("facets");
    assertNotNull("null facet results?", facetResponse);
    assertEquals("numFound mismatch with top count?",
                 rsp.getResults().getNumFound(), ((Number)facetResponse.get("count")).longValue());
    
    return facetResponse;
    
  } catch (Exception e) {
    throw new RuntimeException("query failed: " + params + ": " + 
                               e.getMessage(), e);
  }
}
 
Example #17
Source File: TestSmileRequest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testDistribJsonRequest() throws Exception {
  initServers();
  SolrTestCaseHS.Client client = servers.getClient(random().nextInt());
  client.tester = new SolrTestCaseHS.Client.Tester() {
    @Override
    public void assertJQ(SolrClient client, SolrParams args, String... tests) throws Exception {
      ((HttpSolrClient) client).setParser(SmileResponseParser.inst);
      QueryRequest query = new QueryRequest(args);
      String path = args.get("qt");
      if (path != null) {
        query.setPath(path);
      }
      NamedList<Object> rsp = client.request(query);
      @SuppressWarnings({"rawtypes"})
      Map m = rsp.asMap(5);
      String jsonStr = Utils.toJSONString(m);
      SolrTestCaseHS.matchJSON(jsonStr, tests);
    }
  };
  client.queryDefaults().set("shards", servers.getShards());
  TestJsonRequest.doJsonRequest(client, true);

}
 
Example #18
Source File: TestCollectionAPI.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void testCollectionCreationShardNameValidation() throws Exception {
  try (CloudSolrClient client = createCloudClient(null)) {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("action", CollectionParams.CollectionAction.CREATE.toString());
    params.set("name", "valid_collection_name");
    params.set("router.name", "implicit");
    params.set("numShards", "1");
    params.set("shards", "invalid@name#with$weird%characters");
    @SuppressWarnings({"rawtypes"})
    SolrRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");

    try {
      client.request(request);
      fail();
    } catch (BaseHttpSolrClient.RemoteSolrException e) {
      final String errorMessage = e.getMessage();
      assertTrue(errorMessage.contains("Invalid shard"));
      assertTrue(errorMessage.contains("invalid@name#with$weird%characters"));
      assertTrue(errorMessage.contains("shard names must consist entirely of"));
    }
  }
}
 
Example #19
Source File: TestCollectionAPI.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void testCollectionCreationCollectionNameValidation() throws Exception {
  try (CloudSolrClient client = createCloudClient(null)) {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("action", CollectionParams.CollectionAction.CREATE.toString());
    params.set("name", "invalid@name#with$weird%characters");
    @SuppressWarnings({"rawtypes"})
    SolrRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");

    try {
      client.request(request);
      fail();
    } catch (BaseHttpSolrClient.RemoteSolrException e) {
      final String errorMessage = e.getMessage();
      assertTrue(errorMessage.contains("Invalid collection"));
      assertTrue(errorMessage.contains("invalid@name#with$weird%characters"));
      assertTrue(errorMessage.contains("collection names must consist entirely of"));
    }
  }
}
 
Example #20
Source File: PeerSyncWithLeaderAndIndexFingerprintCachingTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
void assertSync(SolrClient client, int numVersions, boolean expectedResult, String... syncWith) throws IOException, SolrServerException {
  QueryRequest qr = new QueryRequest(params("qt","/get", "getVersions",Integer.toString(numVersions), "syncWithLeader", StrUtils.join(Arrays.asList(syncWith), ',')));
  @SuppressWarnings({"rawtypes"})
  NamedList rsp = client.request(qr);
  assertEquals(expectedResult, (Boolean) rsp.get("syncWithLeader"));
}
 
Example #21
Source File: TestDocLevelOperations.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
private QueryRequest getRealTimeGetRequest(String ids) {
  final ModifiableSolrParams idsParams = new ModifiableSolrParams();
  idsParams.add("ids", ids);
  return new QueryRequest() {
    @Override
    public String getPath() {
      return "/get";
    }

    @Override
    public SolrParams getParams() {
      return idsParams;
    }
  };
}
 
Example #22
Source File: TestDynamicFieldNamesIndexCorrectly.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public SolrDocumentList getSolrResponse(SolrQuery solrQuery, String collection)
    throws SolrServerException, IOException {
  final QueryResponse response;
  SolrDocumentList list = null;
  final QueryRequest req = new QueryRequest(solrQuery);
  cloudClient.setDefaultCollection(collection);
  response = req.process(cloudClient);
  list = response.getResults();
  return list;
}
 
Example #23
Source File: AbstractSolrSentryTestBase.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
/**
 * Method to validate collection Admin operation fail
 * @param solrUserName - User authenticated into Solr
 * @param adminOp - Admin operation to be performed
 * @param collectionName - Name of the collection to be queried
 * @param params - SolrParams to use
 * @throws Exception
 */
protected void verifyCollectionAdminOpFail(String solrUserName,
                                           CollectionAction adminOp,
                                           String collectionName,
                                           SolrParams params) throws Exception {

  String originalUser = getAuthenticatedUser();
  try {
    setAuthenticationUser(solrUserName);
    try {
      QueryRequest request = populateCollectionAdminParams(adminOp, collectionName, params);
      CloudSolrServer solrServer = createNewCloudSolrServer();
      try {
        solrServer.request(request);
        if (adminOp.compareTo(CollectionAction.CREATE) == 0) {
          // Wait for collection creation to complete.
          waitForRecoveriesToFinish(collectionName, solrServer, false);
        }
      } finally {
        solrServer.shutdown();
      }

      fail("The specified user: " + solrUserName + " shouldn't get admin access for " + adminOp);
    } catch (Exception exception) {
      assertTrue("Expected " + SENTRY_ERROR_MSG + " in " + exception.toString(),
          exception.toString().contains(SENTRY_ERROR_MSG));
    }
  } finally {
    setAuthenticationUser(originalUser);
  }
}
 
Example #24
Source File: IterativeMergeStrategy.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public List<Future<CallBack>> callBack(List<ShardResponse> responses, QueryRequest req) {
  @SuppressWarnings({"unchecked", "rawtypes"})
  List<Future<CallBack>> futures = new ArrayList();
  for(ShardResponse response : responses) {
    futures.add(this.executorService.submit(new CallBack(response, req)));
  }
  return futures;
}
 
Example #25
Source File: BasicDistributedZkTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Long getNumCommits(HttpSolrClient sourceClient) throws
    SolrServerException, IOException {
  // construct the /admin/metrics URL
  URL url = new URL(sourceClient.getBaseURL());
  String path = url.getPath().substring(1);
  String[] elements = path.split("/");
  String collection = elements[elements.length - 1];
  String urlString = url.toString();
  urlString = urlString.substring(0, urlString.length() - collection.length() - 1);
  try (HttpSolrClient client = getHttpSolrClient(urlString, 15000, 60000)) {
    ModifiableSolrParams params = new ModifiableSolrParams();
    //params.set("qt", "/admin/metrics?prefix=UPDATE.updateHandler&registry=solr.core." + collection);
    params.set("qt", "/admin/metrics");
    params.set("prefix", "UPDATE.updateHandler");
    params.set("registry", "solr.core." + collection);
    // use generic request to avoid extra processing of queries
    QueryRequest req = new QueryRequest(params);
    NamedList<Object> resp = client.request(req);
    @SuppressWarnings({"rawtypes"})
    NamedList metrics = (NamedList) resp.get("metrics");
    @SuppressWarnings({"rawtypes"})
    NamedList uhandlerCat = (NamedList) metrics.getVal(0);
    @SuppressWarnings({"unchecked"})
    Map<String,Object> commits = (Map<String,Object>) uhandlerCat.get("UPDATE.updateHandler.commits");
    return (Long) commits.get("count");
  }
}
 
Example #26
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 #27
Source File: IndexFetcher.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Fetches the list of files in a given index commit point and updates internal list of files to download.
 */
@SuppressWarnings({"unchecked"})
private void fetchFileList(long gen) throws IOException {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set(COMMAND,  CMD_GET_FILE_LIST);
  params.set(TLOG_FILES, downloadTlogFiles);
  params.set(GENERATION, String.valueOf(gen));
  params.set(CommonParams.WT, JAVABIN);
  params.set(CommonParams.QT, ReplicationHandler.PATH);
  QueryRequest req = new QueryRequest(params);

  // TODO modify to use shardhandler
  try (HttpSolrClient client = new HttpSolrClient.Builder(masterUrl)
      .withHttpClient(myHttpClient)
      .withConnectionTimeout(connTimeout)
      .withSocketTimeout(soTimeout)
      .build()) {
    @SuppressWarnings({"rawtypes"})
    NamedList response = client.request(req);

    List<Map<String, Object>> files = (List<Map<String,Object>>) response.get(CMD_GET_FILE_LIST);
    if (files != null)
      filesToDownload = Collections.synchronizedList(files);
    else {
      filesToDownload = Collections.emptyList();
      log.error("No files to download for index generation: {}", gen);
    }

    files = (List<Map<String,Object>>) response.get(CONF_FILES);
    if (files != null)
      confFilesToDownload = Collections.synchronizedList(files);

    files = (List<Map<String, Object>>) response.get(TLOG_FILES);
    if (files != null) {
      tlogFilesToDownload = Collections.synchronizedList(files);
    }
  } catch (SolrServerException e) {
    throw new IOException(e);
  }
}
 
Example #28
Source File: TestCloudPhrasesIdentificationComponent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testBasicPhrases() throws Exception {
  final String input = " did  a Quick    brown FOX perniciously jump over the lazy dog";
  final String expected = " did  a Quick    {brown FOX} perniciously jump over {the lazy dog}";
  
  // based on the documents indexed, these assertions should all pass regardless of
  // how many shards we have, or wether the request is done via /phrases or /select...
  for (String path : Arrays.asList("/select", "/phrases")) {
    // ... or if we muck with "q" and use the alternative phrases.q for the bits we care about...
    for (SolrParams p : Arrays.asList(params("q", input, "phrases", "true"),
                                      params("q", "*:*", "phrases.q", input, "phrases", "true"),
                                      params("q", "-*:*", "phrases.q", input, "phrases", "true"))) {
      final QueryRequest req = new QueryRequest(p);
      req.setPath(path);
      final QueryResponse rsp = req.process(getRandClient(random()));
      try {
        @SuppressWarnings({"unchecked"})
        NamedList<Object> phrases = (NamedList<Object>) rsp.getResponse().get("phrases");
        assertEquals("input", input, phrases.get("input"));
        assertEquals("summary", expected, phrases.get("summary"));
        
        @SuppressWarnings({"unchecked"})
        final List<NamedList<Object>> details = (List<NamedList<Object>>) phrases.get("details");
        assertNotNull("null details", details);
        assertEquals("num phrases found", 2, details.size());
        
        final NamedList<Object> lazy_dog = details.get(0);
        assertEquals("dog text", "the lazy dog", lazy_dog.get("text"));
        assertEquals("dog score", 0.166666D, ((Double)lazy_dog.get("score")).doubleValue(), 0.000001D);
        
        final NamedList<Object> brown_fox = details.get(1);
        assertEquals("fox text", "brown FOX", brown_fox.get("text"));
        assertEquals("fox score", 0.083333D, ((Double)brown_fox.get("score")).doubleValue(), 0.000001D);
        
      } catch (AssertionError e) {
        throw new AssertionError(e.getMessage() + " ::: " + path + " ==> " + rsp, e);
      }
    }
  }
}
 
Example #29
Source File: PeerSyncWithLeader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private NamedList<Object> request(ModifiableSolrParams params, String onFail) {
  try {
    QueryResponse rsp = new QueryRequest(params, SolrRequest.METHOD.POST).process(clientToLeader);
    Exception exception = rsp.getException();
    if (exception != null) {
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, onFail);
    }
    return rsp.getResponse();
  } catch (SolrServerException | IOException e) {
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, onFail);
  }
}
 
Example #30
Source File: TestRealTimeGet.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
private QueryRequest getRealTimeGetRequest(final SolrParams params) {
  return new QueryRequest() {
    @Override
    public String getPath() {
      return "/get";
    }

    @Override
    public SolrParams getParams() {
      return params;
    }
  };
}