Java Code Examples for org.apache.solr.common.util.NamedList#size()
The following examples show how to use
org.apache.solr.common.util.NamedList#size() .
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: BaseCloudSolrClient.java From lucene-solr with Apache License 2.0 | 6 votes |
public RouteException(ErrorCode errorCode, NamedList<Throwable> throwables, Map<String, ? extends LBSolrClient.Req> routes){ super(errorCode, throwables.getVal(0).getMessage(), throwables.getVal(0)); this.throwables = throwables; this.routes = routes; // create a merged copy of the metadata from all wrapped exceptions NamedList<String> metadata = new NamedList<String>(); for (int i = 0; i < throwables.size(); i++) { Throwable t = throwables.getVal(i); if (t instanceof SolrException) { SolrException e = (SolrException) t; NamedList<String> eMeta = e.getMetadata(); if (null != eMeta) { metadata.addAll(eMeta); } } } if (0 < metadata.size()) { this.setMetadata(metadata); } }
Example 2
Source File: SearchGroupsResultTransformer.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings({"rawtypes"}) public Map<String, SearchGroupsFieldCommandResult> transformToNative(NamedList<NamedList> shardResponse, Sort groupSort, Sort withinGroupSort, String shard) { final Map<String, SearchGroupsFieldCommandResult> result = new HashMap<>(shardResponse.size()); for (Map.Entry<String, NamedList> command : shardResponse) { List<SearchGroup<BytesRef>> searchGroups = new ArrayList<>(); NamedList topGroupsAndGroupCount = command.getValue(); @SuppressWarnings({"unchecked"}) final NamedList<List<Comparable>> rawSearchGroups = (NamedList<List<Comparable>>) topGroupsAndGroupCount.get(TOP_GROUPS); if (rawSearchGroups != null) { final SchemaField groupField = searcher.getSchema().getFieldOrNull(command.getKey()); final SortField[] groupSortField = groupSort.getSort(); for (Map.Entry<String, List<Comparable>> rawSearchGroup : rawSearchGroups){ SearchGroup<BytesRef> searchGroup = deserializeOneSearchGroup( groupField, rawSearchGroup.getKey(), groupSortField, rawSearchGroup.getValue()); searchGroups.add(searchGroup); } } final Integer groupCount = (Integer) topGroupsAndGroupCount.get(GROUP_COUNT); result.put(command.getKey(), new SearchGroupsFieldCommandResult(groupCount, searchGroups)); } return result; }
Example 3
Source File: TestSolrCoreSnapshots.java From lucene-solr with Apache License 2.0 | 6 votes |
private Collection<SnapshotMetaData> listSnapshots(SolrClient adminClient, String coreName) throws Exception { ListSnapshots req = new ListSnapshots(); req.setCoreName(coreName); @SuppressWarnings({"rawtypes"}) NamedList resp = adminClient.request(req); assertTrue( resp.get("snapshots") instanceof NamedList ); @SuppressWarnings({"rawtypes"}) NamedList apiResult = (NamedList) resp.get("snapshots"); List<SnapshotMetaData> result = new ArrayList<>(apiResult.size()); for(int i = 0 ; i < apiResult.size(); i++) { String commitName = apiResult.getName(i); String indexDirPath = (String)((NamedList)apiResult.get(commitName)).get("indexDirPath"); long genNumber = Long.parseLong((String)((NamedList)apiResult.get(commitName)).get("generation")); result.add(new SnapshotMetaData(commitName, indexDirPath, genNumber)); } return result; }
Example 4
Source File: XMLWriter.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void writeNamedList(String name, @SuppressWarnings({"rawtypes"})NamedList val) throws IOException { int sz = val.size(); startTag("lst", name, sz<=0); incLevel(); for (int i=0; i<sz; i++) { writeVal(val.getName(i),val.getVal(i)); } decLevel(); if (sz > 0) { if (doIndent) indent(); writer.write("</lst>"); } }
Example 5
Source File: SolrSnapshotsTool.java From lucene-solr with Apache License 2.0 | 6 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) private Collection<CollectionSnapshotMetaData> listCollectionSnapshots(String collectionName) throws SolrServerException, IOException { CollectionAdminRequest.ListSnapshots listSnapshots = new CollectionAdminRequest.ListSnapshots(collectionName); CollectionAdminResponse resp = listSnapshots.process(solrClient); Preconditions.checkState(resp.getStatus() == 0); NamedList apiResult = (NamedList) resp.getResponse().get(SolrSnapshotManager.SNAPSHOTS_INFO); Collection<CollectionSnapshotMetaData> result = new ArrayList<>(); for (int i = 0; i < apiResult.size(); i++) { result.add(new CollectionSnapshotMetaData((NamedList<Object>)apiResult.getVal(i))); } return result; }
Example 6
Source File: ManagedResource.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Called from {@link #doPut(BaseSolrResource,Representation,Object)} * to update this resource's init args using the given updatedArgs */ @SuppressWarnings("unchecked") protected boolean updateInitArgs(NamedList<?> updatedArgs) { if (updatedArgs == null || updatedArgs.size() == 0) { return false; } boolean madeChanges = false; if (!managedInitArgs.equals(updatedArgs)) { managedInitArgs = (NamedList<Object>)updatedArgs.clone(); madeChanges = true; } return madeChanges; }
Example 7
Source File: DistribCursorPagingTest.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Asks the LukeRequestHandler on the control client for a list of the fields in the * schema and then prunes that list down to just the fields that can be used for sorting, * and returns them as an immutable list in a deterministically random order. */ private List<String> getAllSortFieldNames() throws SolrServerException, IOException { LukeRequest req = new LukeRequest("/admin/luke"); req.setShowSchema(true); NamedList<Object> rsp = controlClient.request(req); @SuppressWarnings({"unchecked"}) NamedList<Object> fields = (NamedList) ((NamedList)rsp.get("schema")).get("fields"); ArrayList<String> names = new ArrayList<>(fields.size()); for (Map.Entry<String,Object> item : fields) { names.add(item.getKey()); } return CursorPagingTest.pruneAndDeterministicallySort(names); }
Example 8
Source File: StatsComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings({"unchecked", "rawtypes"}) public void handleResponses(ResponseBuilder rb, ShardRequest sreq) { if (!rb.doStats || (sreq.purpose & ShardRequest.PURPOSE_GET_STATS) == 0) return; Map<String, StatsValues> allStatsValues = rb._statsInfo.getAggregateStatsValues(); for (ShardResponse srsp : sreq.responses) { NamedList stats = null; try { stats = (NamedList<NamedList<NamedList<?>>>) srsp.getSolrResponse().getResponse().get("stats"); } catch (Exception e) { if (ShardParams.getShardsTolerantAsBool(rb.req.getParams())) { continue; // looks like a shard did not return anything } throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unable to read stats info for shard: " + srsp.getShard(), e); } NamedList stats_fields = unwrapStats(stats); if (stats_fields != null) { for (int i = 0; i < stats_fields.size(); i++) { String key = stats_fields.getName(i); StatsValues stv = allStatsValues.get(key); @SuppressWarnings({"rawtypes"}) NamedList shardStv = (NamedList) stats_fields.get(key); stv.accumulate(shardStv); } } } }
Example 9
Source File: HeatmapJsonFacet.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * A NamedList is a proper "heatmap" response if it contains <i>all</i> expected properties * * We try to be rather strict in determining whether {@code potentialHeatmapValues} is a "heatmap". Users can name * subfacets arbitrarily, so having some names match those expected in a "heatmap" response could just be coincidence. * <p> * Heatmap facets do not support subfacets. */ public static boolean isHeatmapFacet(NamedList<Object> potentialHeatmapValues) { boolean hasGridLevel = false; boolean hasColumns = false; boolean hasRows = false; boolean hasMinX = false; boolean hasMaxX = false; boolean hasMinY = false; boolean hasMaxY = false; boolean hasCountGrid = false; for (Map.Entry<String, Object> entry : potentialHeatmapValues) { String key = entry.getKey(); if ("gridLevel".equals(key)) { hasGridLevel = true; } else if ("columns".equals(key)) { hasColumns = true; } else if ("rows".equals(key)) { hasRows = true; } else if ("minX".equals(key)) { hasMinX = true; } else if ("maxX".equals(key)) { hasMaxX = true; } else if ("minY".equals(key)) { hasMinY = true; } else if ("maxY".equals(key)){ hasMaxY = true; } else if (key != null && key.startsWith("counts_")) { hasCountGrid = true; } } return potentialHeatmapValues.size() == 8 && hasGridLevel && hasColumns && hasRows && hasMinX && hasMaxX && hasMinY && hasMaxY && hasCountGrid; }
Example 10
Source File: SpellCheckResponse.java From lucene-solr with Apache License 2.0 | 5 votes |
@SuppressWarnings({"rawtypes"}) public Suggestion(String token, NamedList<Object> suggestion) { this.token = token; for (int i = 0; i < suggestion.size(); i++) { String n = suggestion.getName(i); if ("numFound".equals(n)) { numFound = (Integer) suggestion.getVal(i); } else if ("startOffset".equals(n)) { startOffset = (Integer) suggestion.getVal(i); } else if ("endOffset".equals(n)) { endOffset = (Integer) suggestion.getVal(i); } else if ("origFreq".equals(n)) { originalFrequency = (Integer) suggestion.getVal(i); } else if ("suggestion".equals(n)) { @SuppressWarnings("unchecked") List list = (List)suggestion.getVal(i); if (list.size() > 0 && list.get(0) instanceof NamedList) { // extended results detected @SuppressWarnings("unchecked") List<NamedList> extended = (List<NamedList>)list; alternativeFrequencies = new ArrayList<>(); for (NamedList nl : extended) { alternatives.add((String)nl.get("word")); alternativeFrequencies.add((Integer)nl.get("freq")); } } else { @SuppressWarnings("unchecked") List<String> alts = (List<String>) list; alternatives.addAll(alts); } } } }
Example 11
Source File: CustomTermsComponentTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private static String extractShardAddresses(final QueryResponse queryResponse, final String delimiter) { final StringBuilder sb = new StringBuilder(); final NamedList<Object> nl = (NamedList<Object>)queryResponse.getResponse().get("shards.info"); assertNotNull(queryResponse.toString(), nl); for (int ii = 0; ii < nl.size(); ++ii) { final String shardAddress = (String)((NamedList<Object>)nl.getVal(ii)).get("shardAddress"); if (sb.length() > 0) { sb.append(delimiter); } sb.append(shardAddress); } return sb.toString(); }
Example 12
Source File: AsyncBuildSuggestComponent.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
/** Convert NamedList (suggester response) to {@link SuggesterResult} */ private SuggesterResult toSuggesterResult(Map<String, SimpleOrderedMap<NamedList<Object>>> suggestionsMap) { SuggesterResult result = new SuggesterResult(); if (suggestionsMap == null) { return result; } // for each token for(Map.Entry<String, SimpleOrderedMap<NamedList<Object>>> entry : suggestionsMap.entrySet()) { String suggesterName = entry.getKey(); for (Iterator<Map.Entry<String, NamedList<Object>>> suggestionsIter = entry.getValue().iterator(); suggestionsIter.hasNext();) { Map.Entry<String, NamedList<Object>> suggestions = suggestionsIter.next(); String tokenString = suggestions.getKey(); List<LookupResult> lookupResults = new ArrayList<>(); NamedList<Object> suggestion = suggestions.getValue(); // for each suggestion for (int j = 0; j < suggestion.size(); j++) { String property = suggestion.getName(j); if (property.equals(SuggesterResultLabels.SUGGESTIONS)) { @SuppressWarnings("unchecked") List<NamedList<Object>> suggestionEntries = (List<NamedList<Object>>) suggestion.getVal(j); for(NamedList<Object> suggestionEntry : suggestionEntries) { String term = (String) suggestionEntry.get(SuggesterResultLabels.SUGGESTION_TERM); Long weight = (Long) suggestionEntry.get(SuggesterResultLabels.SUGGESTION_WEIGHT); String payload = (String) suggestionEntry.get(SuggesterResultLabels.SUGGESTION_PAYLOAD); LookupResult res = new LookupResult(new CharsRef(term), weight, new BytesRef(payload)); lookupResults.add(res); } } result.add(suggesterName, tokenString, lookupResults); } } } return result; }
Example 13
Source File: FacetComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
private void refineFacets(ResponseBuilder rb, ShardRequest sreq) { FacetInfo fi = rb._facetInfo; for (ShardResponse srsp : sreq.responses) { // int shardNum = rb.getShardNum(srsp.shard); NamedList facet_counts = (NamedList) srsp.getSolrResponse().getResponse().get("facet_counts"); NamedList facet_fields = (NamedList) facet_counts.get("facet_fields"); if (facet_fields == null) continue; // this can happen when there's an exception for (int i = 0; i < facet_fields.size(); i++) { String key = facet_fields.getName(i); DistribFieldFacet dff = fi.facets.get(key); if (dff == null) continue; NamedList shardCounts = (NamedList) facet_fields.getVal(i); for (int j = 0; j < shardCounts.size(); j++) { String name = shardCounts.getName(j); long count = ((Number) shardCounts.getVal(j)).longValue(); ShardFacetCount sfc = dff.counts.get(name); if (sfc == null) { // we got back a term we didn't ask for? log.error("Unexpected term returned for facet refining. key='{}' term='{}'\n\trequest params={}\n\ttoRefine={}\n\tresponse={}" , key, name, sreq.params, dff._toRefine, shardCounts); continue; } sfc.count += count; } } } }
Example 14
Source File: ResponseDataGenerator.java From ambari-logsearch with Apache License 2.0 | 5 votes |
public ServiceComponentMetadataWrapper generateGroupedComponentMetadataResponse(QueryResponse queryResponse, String pivotFields, Map<String, String> groupLabels, Map<String, String> componentLabels) { List<ComponentMetadata> componentMetadata = new ArrayList<>(); Map<String, String> groupsMetadata = new HashMap<>(); if (queryResponse == null) { return new ServiceComponentMetadataWrapper(componentMetadata, groupsMetadata); } NamedList<List<PivotField>> facetPivotResponse = queryResponse.getFacetPivot(); if (facetPivotResponse == null || facetPivotResponse.size() < 1) { return new ServiceComponentMetadataWrapper(componentMetadata, groupsMetadata); } if (CollectionUtils.isEmpty(facetPivotResponse.get(pivotFields))) { return new ServiceComponentMetadataWrapper(componentMetadata, groupsMetadata); } for (PivotField pivotField : facetPivotResponse.get(pivotFields)) { if (pivotField != null && pivotField.getValue() != null) { String componentName = pivotField.getValue().toString(); String groupName = null; if (CollectionUtils.isNotEmpty(pivotField.getPivot())) { Object groupValue = pivotField.getPivot().get(0).getValue(); if (groupValue != null) { groupName = groupValue.toString(); groupsMetadata.put(groupName, groupLabels.getOrDefault(groupName, null)); } } String label = componentLabels.get(componentName); String fallbackedLabel = labelFallbackHandler.fallbackIfRequired(componentName, label, true, false, true); componentMetadata.add((new ComponentMetadata(componentName, fallbackedLabel, groupName))); } } return new ServiceComponentMetadataWrapper(componentMetadata, groupsMetadata); }
Example 15
Source File: RewriteFacetCountsComponent.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
private void processPivot(ResponseBuilder rb, String[] fromParts, String[] toParts, Collection<NamedList<Object>> current, int level) { for(NamedList<Object> entry : current) { for(int i = 0; i < entry.size(); i++) { String name = entry.getName(i); if(name.equals("field")) { entry.setVal(i, fromParts[level].trim()); } else if(name.equals("pivot")) { Collection<NamedList<Object>> pivot = (Collection<NamedList<Object>>)entry.getVal(i); processPivot(rb, fromParts, toParts, pivot, level+1); } else if(name.equals("ranges")) { SimpleOrderedMap ranges = (SimpleOrderedMap)entry.getVal(i); processRanges(rb, ranges); } else { // leave alone } } } }
Example 16
Source File: SuggestComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
/** Convert NamedList (suggester response) to {@link SuggesterResult} */ private SuggesterResult toSuggesterResult(Map<String, SimpleOrderedMap<NamedList<Object>>> suggestionsMap) { SuggesterResult result = new SuggesterResult(); if (suggestionsMap == null) { return result; } // for each token for(Map.Entry<String, SimpleOrderedMap<NamedList<Object>>> entry : suggestionsMap.entrySet()) { String suggesterName = entry.getKey(); for (Iterator<Map.Entry<String, NamedList<Object>>> suggestionsIter = entry.getValue().iterator(); suggestionsIter.hasNext();) { Map.Entry<String, NamedList<Object>> suggestions = suggestionsIter.next(); String tokenString = suggestions.getKey(); List<LookupResult> lookupResults = new ArrayList<>(); NamedList<Object> suggestion = suggestions.getValue(); // for each suggestion for (int j = 0; j < suggestion.size(); j++) { String property = suggestion.getName(j); if (property.equals(SuggesterResultLabels.SUGGESTIONS)) { @SuppressWarnings("unchecked") List<NamedList<Object>> suggestionEntries = (List<NamedList<Object>>) suggestion.getVal(j); for(NamedList<Object> suggestionEntry : suggestionEntries) { String term = (String) suggestionEntry.get(SuggesterResultLabels.SUGGESTION_TERM); Long weight = (Long) suggestionEntry.get(SuggesterResultLabels.SUGGESTION_WEIGHT); String payload = (String) suggestionEntry.get(SuggesterResultLabels.SUGGESTION_PAYLOAD); LookupResult res = new LookupResult(new CharsRef(term), weight, new BytesRef(payload)); lookupResults.add(res); } } result.add(suggesterName, tokenString, lookupResults); } } } return result; }
Example 17
Source File: FieldMutatingUpdateProcessorFactory.java From lucene-solr with Apache License 2.0 | 5 votes |
public static Collection<SelectorParams> parseSelectorExclusionParams( @SuppressWarnings({"rawtypes"})NamedList args) { Collection<SelectorParams> exclusions = new ArrayList<>(); @SuppressWarnings({"unchecked"}) List<Object> excList = args.getAll("exclude"); for (Object excObj : excList) { if (null == excObj) { throw new SolrException (SolrException.ErrorCode.SERVER_ERROR, "'exclude' init param can not be null"); } if (! (excObj instanceof NamedList) ) { throw new SolrException (SolrException.ErrorCode.SERVER_ERROR, "'exclude' init param must be <lst/>"); } @SuppressWarnings({"rawtypes"}) NamedList exc = (NamedList) excObj; exclusions.add(parseSelectorParams(exc)); if (0 < exc.size()) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unexpected 'exclude' init sub-param(s): '" + args.getName(0) + "'"); } // call once per instance args.remove("exclude"); } return exclusions; }
Example 18
Source File: AlfrescoCoreAdminHandler.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get a report from a txId with detailed information related with the Transaction * * Synchronous execution * * @param params Query Request with following parameters: * - txId, mandatory, the number of the Transaction to build the report * - core, The name of the SOLR Core or "null" to get the report for every core * @return Response including the action result: * - report: an Object with the details of the report * - error: When mandatory parameters are not set, an error node is returned * * @throws JSONException */ private NamedList<Object> actionTXREPORT(SolrParams params) throws JSONException { NamedList<Object> report = new SimpleOrderedMap<>(); if (params.get(ARG_TXID) == null) { report.add(ACTION_STATUS_ERROR, "No " + ARG_TXID + " parameter set."); return report; } Long txid = Long.valueOf(params.get(ARG_TXID)); String requestedCoreName = coreName(params); coreNames().stream() .filter(coreName -> requestedCoreName == null || coreName.equals(requestedCoreName)) .map(coreName -> new Pair<>(coreName, trackerRegistry.getTrackerForCore(coreName, MetadataTracker.class))) .filter(coreNameAndMetadataTracker -> coreNameAndMetadataTracker.getSecond() != null) .forEach(coreNameAndMetadataTracker -> report.add( coreNameAndMetadataTracker.getFirst(), buildTxReport( trackerRegistry, informationServers.get(coreNameAndMetadataTracker.getFirst()), coreNameAndMetadataTracker.getFirst(), coreNameAndMetadataTracker.getSecond(), txid))); if (report.size() == 0) { addAlertMessage(report); } return report; }
Example 19
Source File: AlfrescoCoreAdminHandler.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get a report from an aclId with the count of documents associated to the ACL * * Synchronous execution * * @param params Query Request with following parameters: * - aclId, mandatory, the number of the ACL to build the report * - core, The name of the SOLR Core or "null" to get the report for every core * @return Response including the action result: * - report: an Object with the details of the report * - error: When mandatory parameters are not set, an error node is returned * * @throws JSONException */ private NamedList<Object> actionACLREPORT(SolrParams params) throws JSONException { NamedList<Object> report = new SimpleOrderedMap<>(); if (params.get(ARG_ACLID) == null) { report.add(ACTION_STATUS_ERROR, "No " + ARG_ACLID + " parameter set."); return report; } Long aclid = Long.valueOf(params.get(ARG_ACLID)); String requestedCoreName = coreName(params); coreNames().stream() .filter(coreName -> requestedCoreName == null || coreName.equals(requestedCoreName)) .map(coreName -> new Pair<>(coreName, trackerRegistry.getTrackerForCore(coreName, AclTracker.class))) .filter(coreNameAndAclTracker -> coreNameAndAclTracker.getSecond() != null) .forEach(coreNameAndAclTracker -> report.add( coreNameAndAclTracker.getFirst(), buildAclReport(coreNameAndAclTracker.getSecond(), aclid))); if (report.size() == 0) { addAlertMessage(report); } return report; }
Example 20
Source File: SolrInfoMBeanHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
protected NamedList<NamedList<NamedList<Object>>> getDiff( NamedList<NamedList<NamedList<Object>>> ref, NamedList<NamedList<NamedList<Object>>> now, boolean includeAll ) { NamedList<NamedList<NamedList<Object>>> changed = new NamedList<>(); // Cycle through each category for(int i=0;i<ref.size();i++) { String category = ref.getName(i); NamedList<NamedList<Object>> ref_cat = ref.get(category); NamedList<NamedList<Object>> now_cat = now.get(category); if(now_cat != null) { String ref_txt = ref_cat+""; String now_txt = now_cat+""; if(!ref_txt.equals(now_txt)) { // Something in the category changed // Now iterate the real beans NamedList<NamedList<Object>> cat = new SimpleOrderedMap<>(); for(int j=0;j<ref_cat.size();j++) { String name = ref_cat.getName(j); NamedList<Object> ref_bean = ref_cat.get(name); NamedList<Object> now_bean = now_cat.get(name); ref_txt = ref_bean+""; now_txt = now_bean+""; if(!ref_txt.equals(now_txt)) { // System.out.println( "----" ); // System.out.println( category +" : " + name ); // System.out.println( "REF: " + ref_txt ); // System.out.println( "NOW: " + now_txt ); // Calculate the differences @SuppressWarnings({"rawtypes"}) NamedList diff = diffNamedList(ref_bean,now_bean); diff.add( "_changed_", true ); // flag the changed thing cat.add(name, diff); } else if(includeAll) { cat.add(name, ref_bean); } } if(cat.size()>0) { changed.add(category, cat); } } else if(includeAll) { changed.add(category, ref_cat); } } } return changed; }