Java Code Examples for org.apache.solr.common.util.NamedList#findRecursive()

The following examples show how to use org.apache.solr.common.util.NamedList#findRecursive() . 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: MtasSolrComponentPrefix.java    From mtas with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void finishStage(ResponseBuilder rb) {
  if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
      && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY
      && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
    for (ShardRequest sreq : rb.finished) {
      if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
          && sreq.params.getBool(PARAM_MTAS_PREFIX, false)) {
        for (ShardResponse shardResponse : sreq.responses) {
          NamedList<Object> response = shardResponse.getSolrResponse()
              .getResponse();
          try {
            ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response
                .findRecursive("mtas", NAME);
            if (data != null) {
              MtasSolrResultUtil.decode(data);
            }
          } catch (ClassCastException e) {
            log.debug(e);
            // shouldnt happen
          }
        }
      }
    }
  }
}
 
Example 2
Source File: LegacyAbstractAnalyticsFacetCloudTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected <T> ArrayList<T> getValueList(NamedList<Object> response, String infoName, String facetType, String facetName, String exprName, boolean includeMissing) {
  NamedList<NamedList<Object>> facetList =
      (NamedList<NamedList<Object>>)response.findRecursive(AnalyticsResponseHeadings.COMPLETED_OLD_HEADER,
                                                           infoName,
                                                           facetType,
                                                           facetName);

  ArrayList<T> results = new ArrayList<>();
  facetList.forEach( (name, expressions) -> {
    if (!includeMissing && !name.equals("(MISSING)")) {
      T result = (T)expressions.get(exprName);
      if (result != null)
        results.add(result);
    }
  });
  return results;
}
 
Example 3
Source File: MtasSolrComponentStats.java    From mtas with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void finishStage(ResponseBuilder rb) {
  if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
      && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY
      && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
    for (ShardRequest sreq : rb.finished) {
      if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
          && sreq.params.getBool(PARAM_MTAS_STATS, false)) {
        for (ShardResponse shardResponse : sreq.responses) {
          NamedList<Object> response = shardResponse.getSolrResponse()
              .getResponse();
          try {
            ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response
                .findRecursive("mtas", NAME);
            if (data != null) {
              MtasSolrResultUtil.decode(data);
            }
          } catch (ClassCastException e) {
            log.debug(e);
            // shouldnt happen
          }
        }
      }
    }
  }
}
 
Example 4
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 5
Source File: MtasSolrComponentFacet.java    From mtas with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void finishStage(ResponseBuilder rb) {
  if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
      && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY
      && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
    for (ShardRequest sreq : rb.finished) {
      if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
          && sreq.params.getBool(PARAM_MTAS_FACET, false)) {
        for (ShardResponse shardResponse : sreq.responses) {
          NamedList<Object> response = shardResponse.getSolrResponse()
              .getResponse();
          try {
            ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response
                .findRecursive("mtas", NAME);
            if (data != null) {
              MtasSolrResultUtil.decode(data);
            }
          } catch (ClassCastException e) {
            log.debug(e);
            // shouldn't happen
          }
        }
      }
    }
  }
}
 
Example 6
Source File: SolrDocumentSearch.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private List<Object> findFacetTree(QueryResponse response, String field) {
	NamedList<Object> baseResponse = response.getResponse();
	NamedList<Object> facetTrees = (NamedList<Object>) baseResponse.findRecursive("facet_counts", "facet_trees");
	
	return facetTrees == null ? null : facetTrees.getAll(field);
}
 
Example 7
Source File: MtasSolrComponentVersion.java    From mtas with Apache License 2.0 5 votes vote down vote up
@Override
public void finishStage(ResponseBuilder rb) {
	if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) {
		if (rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
			for (ShardRequest sreq : rb.finished) {
				if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
						&& sreq.params.getBool(PARAM_MTAS_VERSION, false)) {
					for (ShardResponse shardResponse : sreq.responses) {
						NamedList<Object> solrShardResponse = shardResponse.getSolrResponse().getResponse();
						try {
							SimpleOrderedMap<Object> data = (SimpleOrderedMap<Object>) solrShardResponse
									.findRecursive(MtasSolrSearchComponent.NAME, NAME);
							// create shardInfo
							SimpleOrderedMap<Object> dataShard = new SimpleOrderedMap<>();
							dataShard.add(NAME_MTAS_VERSION_SHARD, shardResponse.getShard());
							dataShard.add(NAME, data.clone());
							List<SimpleOrderedMap> dataShards = new ArrayList<>();
							dataShards.add(dataShard);
							// create main data
							data.clear();
							data.addAll(getVersion());
							// add shardInfo
							data.add(NAME_MTAS_VERSION_SHARDS, dataShards);
						} catch (ClassCastException | IOException e) {
							log.debug(e);
							// shouldn't happen
						}

					}
				}
			}

		}
	}

}
 
Example 8
Source File: MtasSolrComponentGroup.java    From mtas with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void finishStage(ResponseBuilder rb) {
  if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
      && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY
      && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
    // decode finished results
    for (ShardRequest sreq : rb.finished) {
      if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
          && sreq.params.getBool(PARAM_MTAS_GROUP, false)) {
        for (ShardResponse shardResponse : sreq.responses) {
          NamedList<Object> response = shardResponse.getSolrResponse()
              .getResponse();
          try {
            ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response
                .findRecursive("mtas", NAME);
            if (data != null) {
              MtasSolrResultUtil.decode(data);
            }
          } catch (ClassCastException e) {
            log.debug(e);
            // shouldn't happen
          }
        }
      }
    }
  }
}
 
Example 9
Source File: CloudSolrClientTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Long getNumRequests(String baseUrl, String collectionName, String category, String key, String scope, boolean returnNumErrors) throws
    SolrServerException, IOException {

  NamedList<Object> resp;
  try (HttpSolrClient client = getHttpSolrClient(baseUrl + "/"+ collectionName, 15000, 60000)) {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("qt", "/admin/mbeans");
    params.set("stats", "true");
    params.set("key", key);
    params.set("cat", category);
    // use generic request to avoid extra processing of queries
    QueryRequest req = new QueryRequest(params);
    resp = client.request(req);
  }
  String name;
  if (returnNumErrors) {
    name = category + "." + (scope != null ? scope : key) + ".errors";
  } else {
    name = category + "." + (scope != null ? scope : key) + ".requests";
  }
  @SuppressWarnings({"unchecked"})
  Map<String,Object> map = (Map<String,Object>)resp.findRecursive("solr-mbeans", category, key, "stats");
  if (map == null) {
    return null;
  }
  if (scope != null) { // admin handler uses a meter instead of counter here
    return (Long)map.get(name + ".count");
  } else {
    return (Long) map.get(name);
  }
}
 
Example 10
Source File: MetricsHistoryWithAuthIntegrationTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testValuesAreCollected() throws Exception {
  NamedList<Object> rsp = solrClient.request(createHistoryRequest(params(
      CommonParams.ACTION, "get", CommonParams.NAME, "solr.jvm")));
  assertNotNull(rsp);
  // default format is LIST
  NamedList<Object> data = (NamedList<Object>)rsp.findRecursive("metrics", "solr.jvm", "data");
  assertNotNull(data);

  // Has actual values. These will be 0.0 if metrics could not be collected
  NamedList<Object> memEntry = (NamedList<Object>) ((NamedList<Object>) data.iterator().next().getValue()).get("values");
  List<Double> heap = (List<Double>) memEntry.getAll("memory.heap.used").get(0);
  assertTrue("Expected memory.heap.used > 0 in history", heap.get(240) > 0.01);
}
 
Example 11
Source File: BackupStatusChecker.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Does a single check of the replication handler's status to determine if the specified name matches 
 * the most recently deleted backup, and if deleting that backup was a success.
 * Throws a test assertion failure if the status is about this backupName but the starts message 
 * with <code>"Unable to delete"</code>
 *
 * @returns true if the replication status info indicates the backup was deleted, false otherwise
 * @see #waitForBackupDeletionSuccess(String,TimeOut)
 */
public boolean checkBackupDeletionSuccess(final String backupName) throws Exception {
  assertNotNull("backumpName must not be null", backupName);
  final SimpleSolrResponse rsp = new GenericSolrRequest(GenericSolrRequest.METHOD.GET, path,
                                                        params("command", "details")).process(client);
  @SuppressWarnings({"rawtypes"})
  final NamedList data = rsp.getResponse();
  log.info("Checking Deletion Status of {}: {}", backupName, data);
  @SuppressWarnings({"unchecked"})
  final NamedList<String> backupData = (NamedList<String>) data.findRecursive("details","backup");
  if (null == backupData
      || null == backupData.get("status")
      || ! backupName.equals(backupData.get("snapshotName")) ) {
    // either no backup activity at all,
    // or most recent activity isn't something we can infer anything from,
    // or is not about the backup we care about...
    return false;
  }
  
  final Object status = backupData.get("status");
  if (status.toString().startsWith("Unable to delete")) {
    // we already know backupData is about our backup
    assertNull("Backup Deleting failure: " + backupName, status);
  }

  if ("success".equals(status) && null != backupData.get("snapshotDeletedAt")) {
    return true; // backup done
  }
  
  // if we're still here then this status is about our backup, but doesn't seem to be a deletion
  return false;
}
 
Example 12
Source File: FieldAnalysisRequestHandlerTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test //See SOLR-8460
public void testCustomAttribute() throws Exception {
  FieldAnalysisRequest request = new FieldAnalysisRequest();
  request.addFieldType("skutype1");
  request.setFieldValue("hi, 3456-12 a Test");
  request.setShowMatch(false);
  FieldType fieldType = new TextField();
  Analyzer analyzer = new TokenizerChain(
      new TokenizerFactory(Collections.emptyMap()) {
        @Override
        public Tokenizer create(AttributeFactory factory) {
          return new CustomTokenizer(factory);
        }
      },
      new TokenFilterFactory[] {
          new TokenFilterFactory(Collections.emptyMap()) {
            @Override
            public TokenStream create(TokenStream input) {
              return new CustomTokenFilter(input);
            }
          }
      }
  );
  fieldType.setIndexAnalyzer(analyzer);

  @SuppressWarnings({"rawtypes"})
  NamedList<NamedList> result = handler.analyzeValues(request, fieldType, "fieldNameUnused");
  // just test that we see "900" in the flags attribute here
  @SuppressWarnings({"unchecked", "rawtypes"})
  List<NamedList> tokenInfoList = (List<NamedList>) result.findRecursive("index", CustomTokenFilter.class.getName());
  // '1' from CustomTokenFilter plus 900 from CustomFlagsAttributeImpl.
  assertEquals(901, tokenInfoList.get(0).get("org.apache.lucene.analysis.tokenattributes.FlagsAttribute#flags"));
}
 
Example 13
Source File: LegacyAbstractAnalyticsFacetCloudTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected boolean responseContainsFacetValue(NamedList<Object> response, String infoName, String facetType, String facetName, String facetValue) {
  return null != response.findRecursive(AnalyticsResponseHeadings.COMPLETED_OLD_HEADER,
                                        infoName,
                                        facetType,
                                        facetName,
                                        facetValue);
}
 
Example 14
Source File: MtasSolrComponentPrefix.java    From mtas with Apache License 2.0 5 votes vote down vote up
/**
 * Repair prefix items.
 *
 * @param mtasResponse the mtas response
 */
@SuppressWarnings("unchecked")
private void repairPrefixItems(NamedList<Object> mtasResponse) {
  // repair prefix lists
  try {
    ArrayList<NamedList<?>> list = (ArrayList<NamedList<?>>) mtasResponse
        .findRecursive(NAME);
    // MtasSolrResultUtil.rewrite(list);
    if (list != null) {
      for (NamedList<?> item : list) {
        SortedSet<String> singlePosition = (SortedSet<String>) item
            .get("singlePosition");
        SortedSet<String> multiplePosition = (SortedSet<String>) item
            .get("multiplePosition");
        if (singlePosition != null && multiplePosition != null) {
          for (String prefix : multiplePosition) {
            if (singlePosition.contains(prefix)) {
              singlePosition.remove(prefix);
            }
          }
        }
      }
    }
  } catch (ClassCastException e) {
    log.debug(e);
  }
}
 
Example 15
Source File: CloudHttp2SolrClientTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Long getNumRequests(String baseUrl, String collectionName, String category, String key, String scope, boolean returnNumErrors) throws
    SolrServerException, IOException {

  NamedList<Object> resp;
  try (HttpSolrClient client = getHttpSolrClient(baseUrl + "/"+ collectionName, 15000, 60000)) {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("qt", "/admin/mbeans");
    params.set("stats", "true");
    params.set("key", key);
    params.set("cat", category);
    // use generic request to avoid extra processing of queries
    QueryRequest req = new QueryRequest(params);
    resp = client.request(req);
  }
  String name;
  if (returnNumErrors) {
    name = category + "." + (scope != null ? scope : key) + ".errors";
  } else {
    name = category + "." + (scope != null ? scope : key) + ".requests";
  }
  @SuppressWarnings({"unchecked"})
  Map<String,Object> map = (Map<String,Object>)resp.findRecursive("solr-mbeans", category, key, "stats");
  if (map == null) {
    return null;
  }
  if (scope != null) { // admin handler uses a meter instead of counter here
    return (Long)map.get(name + ".count");
  } else {
    return (Long) map.get(name);
  }
}
 
Example 16
Source File: ReplicationFactorTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void assertMinRfInResponse(int minRf, NamedList<Object> response) {
  Object minRfFromResponse = response.findRecursive("responseHeader", UpdateRequest.MIN_REPFACT);
  assertNotNull("Expected min_rf header in the response", minRfFromResponse);
  assertEquals("Unexpected min_rf in response", ((Integer)minRfFromResponse).intValue(), minRf);
}
 
Example 17
Source File: MtasSolrStatus.java    From mtas with Apache License 2.0 3 votes vote down vote up
/**
 * Gets the long.
 *
 * @param response
 *          the response
 * @param args
 *          the args
 * @return the long
 */
private final Long getLong(NamedList<Object> response, String... args) {
  Object objectItem = response.findRecursive(args);
  if (objectItem != null && objectItem instanceof Long) {
    return (Long) objectItem;
  } else {
    return null;
  }
}
 
Example 18
Source File: MtasSolrStatus.java    From mtas with Apache License 2.0 3 votes vote down vote up
/**
 * Gets the long map.
 *
 * @param response
 *          the response
 * @param args
 *          the args
 * @return the long map
 */
private final Map<String, Long> getLongMap(NamedList<Object> response, String... args) {
  Object objectItem = response.findRecursive(args);
  if (objectItem != null && objectItem instanceof Map) {
    return (Map) objectItem;
  } else {
    return null;
  }
}
 
Example 19
Source File: MtasSolrStatus.java    From mtas with Apache License 2.0 3 votes vote down vote up
/**
 * Gets the string.
 *
 * @param response
 *          the response
 * @param args
 *          the args
 * @return the string
 */
private final String getString(NamedList<Object> response, String... args) {
  Object objectItem = response.findRecursive(args);
  if (objectItem != null && objectItem instanceof String) {
    return (String) objectItem;
  } else {
    return null;
  }
}
 
Example 20
Source File: MtasSolrStatus.java    From mtas with Apache License 2.0 3 votes vote down vote up
/**
 * Gets the boolean.
 *
 * @param response
 *          the response
 * @param args
 *          the args
 * @return the boolean
 */
private final Boolean getBoolean(NamedList<Object> response, String... args) {
  Object objectItem = response.findRecursive(args);
  Boolean result = null;
  if (objectItem != null && objectItem instanceof Boolean) {
    result = (Boolean) objectItem;
  }
  return result;
}