Java Code Examples for org.apache.solr.common.util.NamedList#iterator()
The following examples show how to use
org.apache.solr.common.util.NamedList#iterator() .
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: MtasSolrResultUtil.java From mtas with Apache License 2.0 | 6 votes |
/** * Rewrite to array. * * @param nnl the nnl * @return the array list */ private static ArrayList<NamedList<Object>> rewriteToArray( NamedList<Object> nnl) { ArrayList<NamedList<Object>> al = new ArrayList<>(); String key; Iterator<Entry<String, Object>> it = nnl.iterator(); while (it.hasNext()) { Entry<String, Object> entry = it.next(); NamedList<Object> item = (NamedList<Object>) entry.getValue(); key = entry.getKey(); if (key.startsWith(GroupHit.KEY_START)) { StringBuilder newKey = new StringBuilder(""); item.add("group", GroupHit.keyToObject(key, newKey)); item.add("key", newKey.toString().trim()); } else { item.add("key", key); } al.add(item); } return al; }
Example 2
Source File: HttpShardHandlerFactory.java From lucene-solr with Apache License 2.0 | 5 votes |
@SuppressWarnings({"unchecked"}) private void initReplicaListTransformers(@SuppressWarnings({"rawtypes"})NamedList routingConfig) { String defaultRouting = null; ReplicaListTransformerFactory stableRltFactory = null; ReplicaListTransformerFactory defaultRltFactory; if (routingConfig != null && routingConfig.size() > 0) { Iterator<Entry<String,?>> iter = routingConfig.iterator(); do { Entry<String, ?> e = iter.next(); String key = e.getKey(); switch (key) { case ShardParams.REPLICA_RANDOM: // Only positive assertion of default status (i.e., default=true) is supported. // "random" is currently the implicit default, so explicitly configuring // "random" as default would not currently be useful, but if the implicit default // changes in the future, checkDefault could be relevant here. defaultRouting = checkDefaultReplicaListTransformer(getNamedList(e.getValue()), key, defaultRouting); break; case ShardParams.REPLICA_STABLE: NamedList<?> c = getNamedList(e.getValue()); defaultRouting = checkDefaultReplicaListTransformer(c, key, defaultRouting); stableRltFactory = new AffinityReplicaListTransformerFactory(c); break; default: throw new IllegalArgumentException("invalid replica routing spec name: " + key); } } while (iter.hasNext()); } if (stableRltFactory == null) { stableRltFactory = new AffinityReplicaListTransformerFactory(); } if (ShardParams.REPLICA_STABLE.equals(defaultRouting)) { defaultRltFactory = stableRltFactory; } else { defaultRltFactory = RequestReplicaListTransformerGenerator.RANDOM_RLTF; } this.requestReplicaListTransformerGenerator = new RequestReplicaListTransformerGenerator(defaultRltFactory, stableRltFactory); }
Example 3
Source File: OverseerConfigSetMessageHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
private void mergeOldProperties(Map<String, Object> newProps, @SuppressWarnings({"rawtypes"})NamedList oldProps) { @SuppressWarnings({"unchecked"}) Iterator<Map.Entry<String, Object>> it = oldProps.iterator(); while (it.hasNext()) { Map.Entry<String, Object> oldEntry = it.next(); if (!newProps.containsKey(oldEntry.getKey())) { newProps.put(oldEntry.getKey(), oldEntry.getValue()); } } }
Example 4
Source File: FacetTreeGenerator.java From BioSolr with Apache License 2.0 | 5 votes |
/** * Convert a list of facets into a map, keyed by the facet term. * @param facetValues the facet values. * @return a map of term - value for each entry. */ private Map<String, Integer> extractFacetValues(NamedList<Integer> facetValues) { Map<String, Integer> facetMap = new LinkedHashMap<>(); for (Iterator<Entry<String, Integer>> it = facetValues.iterator(); it.hasNext(); ) { Entry<String, Integer> entry = it.next(); if (entry.getValue() > 0) { facetMap.put(entry.getKey(), entry.getValue()); } } return facetMap; }
Example 5
Source File: BaseCloudSolrClient.java From lucene-solr with Apache License 2.0 | 4 votes |
/** * Walks the NamedList response after performing an update request looking for * the replication factor that was achieved in each shard involved in the request. * For single doc updates, there will be only one shard in the return value. */ @SuppressWarnings({"unchecked", "rawtypes"}) public Map<String,Integer> getShardReplicationFactor(String collection, NamedList resp) { connect(); Map<String,Integer> results = new HashMap<String,Integer>(); if (resp instanceof RouteResponse) { NamedList routes = ((RouteResponse)resp).getRouteResponses(); DocCollection coll = getDocCollection(collection, null); Map<String,String> leaders = new HashMap<String,String>(); for (Slice slice : coll.getActiveSlicesArr()) { Replica leader = slice.getLeader(); if (leader != null) { ZkCoreNodeProps zkProps = new ZkCoreNodeProps(leader); String leaderUrl = zkProps.getBaseUrl() + "/" + zkProps.getCoreName(); leaders.put(leaderUrl, slice.getName()); String altLeaderUrl = zkProps.getBaseUrl() + "/" + collection; leaders.put(altLeaderUrl, slice.getName()); } } @SuppressWarnings({"unchecked"}) Iterator<Map.Entry<String,Object>> routeIter = routes.iterator(); while (routeIter.hasNext()) { Map.Entry<String,Object> next = routeIter.next(); String host = next.getKey(); NamedList hostResp = (NamedList)next.getValue(); Integer rf = (Integer)((NamedList)hostResp.get("responseHeader")).get(UpdateRequest.REPFACT); if (rf != null) { String shard = leaders.get(host); if (shard == null) { if (host.endsWith("/")) shard = leaders.get(host.substring(0,host.length()-1)); if (shard == null) { shard = host; } } results.put(shard, rf); } } } return results; }
Example 6
Source File: MtasSolrBase.java From mtas with Apache License 2.0 | 4 votes |
/** * Gets the from mtas prefix. * * @param response the response * @param key the key * @return the from mtas prefix */ public static Map<String, List<String>> getFromMtasPrefix( NamedList<Object> response, String key) { if (response == null) { log.error("no (valid); response"); } else { Object mtasResponseRaw = response.get("mtas"); if (mtasResponseRaw != null && mtasResponseRaw instanceof NamedList) { NamedList<Object> mtasResponse = (NamedList) response.get("mtas"); Object mtasPrefixResponseRaw = mtasResponse.get("prefix"); if (mtasPrefixResponseRaw != null && mtasPrefixResponseRaw instanceof List) { List<NamedList> mtasPrefixResponse = (List) mtasPrefixResponseRaw; if (mtasPrefixResponse.isEmpty()) { log.error("no (valid) mtas prefix response"); } else { NamedList<Object> item = null; for (NamedList<Object> mtasPrefixResponseItem : mtasPrefixResponse) { if (mtasPrefixResponseItem.get("key") != null && (mtasPrefixResponseItem.get("key") instanceof String) && mtasPrefixResponseItem.get("key").equals(key)) { item = mtasPrefixResponseItem; break; } } assertFalse("no item with key " + key, item == null); Map<String, List<String>> result = new HashMap<>(); if (item != null) { Iterator<Entry<String, Object>> it = item.iterator(); Entry<String, Object> entry; while (it.hasNext()) { entry = it.next(); if (!entry.getKey().equals("key")) { assertTrue("invalid entry prefix", entry.getValue() instanceof List); result.put(entry.getKey(), (List) entry.getValue()); } } } return result; } } } } return null; }
Example 7
Source File: RangerSolrAuthorizer.java From ranger with Apache License 2.0 | 4 votes |
@Override public void init(NamedList args) { SolrParams params = args.toSolrParams(); this.authField = params.get(AUTH_FIELD_PROP, DEFAULT_AUTH_FIELD); this.allRolesToken = params.get(ALL_ROLES_TOKEN_PROP, ""); this.enabled = params.getBool(ENABLED_PROP, false); this.matchMode = MatchType.valueOf(params.get(MODE_PROP, DEFAULT_MODE_PROP).toUpperCase()); if (this.matchMode == MatchType.CONJUNCTIVE) { this.qParserName = params.get(QPARSER_PROP, "subset").trim(); this.allowMissingValue = params.getBool(ALLOW_MISSING_VAL_PROP, false); this.tokenCountField = params.get(TOKEN_COUNT_PROP, DEFAULT_TOKEN_COUNT_FIELD_PROP); } this.attrsEnabled = params.getBool(ATTRS_ENABLED_PROP, false); logger.info("RangerSolrAuthorizer.init(): authField={" + authField + "}, allRolesToken={" + allRolesToken + "}, enabled={" + enabled + "}, matchType={" + matchMode + "}, qParserName={" + qParserName + "}, allowMissingValue={" + allowMissingValue + "}, tokenCountField={" + tokenCountField + "}, attrsEnabled={" + attrsEnabled + "}"); if (attrsEnabled) { if (params.get(FIELD_ATTR_MAPPINGS) != null) { logger.info("Solr params = " + params.get(FIELD_ATTR_MAPPINGS)); NamedList mappings = checkAndGet(args, FIELD_ATTR_MAPPINGS); Iterator<Map.Entry<String, NamedList>> iter = mappings.iterator(); while (iter.hasNext()) { Map.Entry<String, NamedList> entry = iter.next(); String solrFieldName = entry.getKey(); String attributeNames = checkAndGet(entry.getValue(), ATTR_NAMES); String filterType = checkAndGet(entry.getValue(), FIELD_FILTER_TYPE); boolean acceptEmpty = false; if (entry.getValue().getBooleanArg(PERMIT_EMPTY_VALUES) != null) { acceptEmpty = entry.getValue().getBooleanArg(PERMIT_EMPTY_VALUES); } String allUsersValue = getWithDefault(entry.getValue(), ALL_USERS_VALUE, ""); String regex = getWithDefault(entry.getValue(), ATTRIBUTE_FILTER_REGEX, ""); String extraOpts = getWithDefault(entry.getValue(), EXTRA_OPTS, ""); FieldToAttributeMapping mapping = new FieldToAttributeMapping(solrFieldName, attributeNames, filterType, acceptEmpty, allUsersValue, regex, extraOpts); fieldAttributeMappings.add(mapping); } } this.andQParserName = this.<String>checkAndGet(args, AND_OP_QPARSER).trim(); } }