Java Code Examples for org.apache.solr.common.util.NamedList#getName()
The following examples show how to use
org.apache.solr.common.util.NamedList#getName() .
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: 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 2
Source File: TestSolrCloudSnapshots.java From lucene-solr with Apache License 2.0 | 6 votes |
private Collection<SnapshotMetaData> listCoreSnapshots(SolrClient adminClient, String coreName) throws Exception { ListSnapshots req = new ListSnapshots(); req.setCoreName(coreName); @SuppressWarnings({"rawtypes"}) NamedList resp = adminClient.request(req); assertTrue( resp.get(SolrSnapshotManager.SNAPSHOTS_INFO) instanceof NamedList ); @SuppressWarnings({"rawtypes"}) NamedList apiResult = (NamedList) resp.get(SolrSnapshotManager.SNAPSHOTS_INFO); 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(SolrSnapshotManager.INDEX_DIR_PATH); long genNumber = Long.parseLong((String)((NamedList)apiResult.get(commitName)).get(SolrSnapshotManager.GENERATION_NUM)); result.add(new SnapshotMetaData(commitName, indexDirPath, genNumber)); } return result; }
Example 3
Source File: MCRSolrProxyServlet.java From mycore with GNU General Public License v3.0 | 6 votes |
static Map<String, String[]> toMultiMap(ModifiableSolrParams solrQueryParameter) { NamedList<Object> namedList = solrQueryParameter.toNamedList(); //disabled for MCR-953 and https://issues.apache.org/jira/browse/SOLR-7508 //Map<String, String[]> parameters = ModifiableSolrParams.toMultiMap(namedList); HashMap<String, String[]> parameters = new HashMap<>(); for (int i = 0; i < namedList.size(); i++) { String name = namedList.getName(i); Object val = namedList.getVal(i); if (val instanceof String[]) { MultiMapSolrParams.addParam(name, (String[]) val, parameters); } else { MultiMapSolrParams.addParam(name, val.toString(), parameters); } } //end of fix return parameters; }
Example 4
Source File: AbstractDefaultValueUpdateProcessorFactory.java From lucene-solr with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public void init(@SuppressWarnings({"rawtypes"})NamedList args) { Object obj = args.remove("fieldName"); if (null == obj && null == fieldName) { throw new SolrException (SERVER_ERROR, "'fieldName' init param must be specified and non-null"); } else { fieldName = obj.toString(); } if (0 < args.size()) { throw new SolrException(SERVER_ERROR, "Unexpected init param(s): '" + args.getName(0) + "'"); } super.init(args); }
Example 5
Source File: TermsResponse.java From lucene-solr with Apache License 2.0 | 6 votes |
public TermsResponse(NamedList<NamedList<Object>> termsInfo) { for (int i = 0; i < termsInfo.size(); i++) { String fieldName = termsInfo.getName(i); List<Term> itemList = new ArrayList<>(); NamedList<Object> items = termsInfo.getVal(i); for (int j = 0; j < items.size(); j++) { String term = items.getName(j); Object val = items.getVal(j); Term t; if (val instanceof NamedList) { @SuppressWarnings("unchecked") NamedList<Number> termStats = (NamedList<Number>) val; t = new Term(term, termStats.get("df").longValue(), termStats.get("ttf").longValue()); } else { t = new Term(term, ((Number) val).longValue()); } itemList.add(t); } termMap.put(fieldName, itemList); } }
Example 6
Source File: CloneFieldUpdateProcessorFactory.java From lucene-solr with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public void init(@SuppressWarnings({"rawtypes"})NamedList args) { // high level (loose) check for which type of config we have. // // individual init methods do more strict syntax checking if (0 <= args.indexOf(SOURCE_PARAM, 0) && 0 <= args.indexOf(DEST_PARAM, 0) ) { initSourceSelectorSyntax(args); } else if (0 <= args.indexOf(PATTERN_PARAM, 0) && 0 <= args.indexOf(REPLACEMENT_PARAM, 0)) { initSimpleRegexReplacement(args); } else { throw new SolrException(SERVER_ERROR, "A combination of either '" + SOURCE_PARAM + "' + '"+ DEST_PARAM + "', or '" + REPLACEMENT_PARAM + "' + '" + PATTERN_PARAM + "' init params are mandatory"); } if (0 < args.size()) { throw new SolrException(SERVER_ERROR, "Unexpected init param(s): '" + args.getName(0) + "'"); } super.init(args); }
Example 7
Source File: SolrParams.java From lucene-solr with Apache License 2.0 | 6 votes |
/** Create a Map<String,String[]> from a NamedList */ @Deprecated // Doesn't belong here (no SolrParams). Just remove. public static Map<String,String[]> toMultiMap(@SuppressWarnings({"rawtypes"})NamedList params) { HashMap<String,String[]> map = new HashMap<>(); for (int i=0; i<params.size(); i++) { String name = params.getName(i); Object val = params.getVal(i); if (val instanceof String[]) { MultiMapSolrParams.addParam(name, (String[]) val, map); } else if (val instanceof List) { @SuppressWarnings({"rawtypes"}) List l = (List) val; String[] s = new String[l.size()]; for (int j = 0; j < l.size(); j++) { s[j] = l.get(j) == null ? null : String.valueOf(l.get(j)); } MultiMapSolrParams.addParam(name, s, map); } else { MultiMapSolrParams.addParam(name, val.toString(), map); } } return map; }
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: RewriteFacetCountsComponent.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
/** * @param rb */ private void copyAnalytics(ResponseBuilder rb, String ... sections) { NamedList<Object> found = (NamedList<Object>) rb.rsp.getValues(); for(String section : sections) { found = (NamedList<Object>)found.get(section); if(found == null) { return; } } NamedList<Object> analytics = (NamedList<Object>) rb.rsp.getValues(); analytics = (NamedList<Object>)analytics.get("analytics"); if(analytics != null) { for(int i = 0; i < analytics.size(); i++) { String name = analytics.getName(i); Object value = analytics.getVal(i); found.add(name, value); } } }
Example 10
Source File: IgnoreLargeDocumentProcessorFactory.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void init(@SuppressWarnings({"rawtypes"})NamedList args) { maxDocumentSize = args.toSolrParams().required().getLong(LIMIT_SIZE_PARAM); args.remove(LIMIT_SIZE_PARAM); if (args.size() > 0) { throw new SolrException(SERVER_ERROR, "Unexpected init param(s): '" + args.getName(0) + "'"); } }
Example 11
Source File: SchemaXmlWriter.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void writeNamedList(String name, @SuppressWarnings({"rawtypes"})NamedList val) throws IOException { // name is ignored - this method is only used for SimilarityFactory int sz = val.size(); for (int i=0; i<sz; i++) { String valName = val.getName(i); if ( ! valName.equals(SimilarityFactory.CLASS_NAME)) { writeVal(valName, val.getVal(i)); } } }
Example 12
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 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: 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 15
Source File: RewriteFacetCountsComponent.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
/** * Update entries in a list to reference ACS properties rather than Solr fields. * * @param mappings The mapping from ACS properties to Solr fields. * @param propertyList The list to update. */ private void updateToACSNaming(BiMap<String, String> mappings, NamedList<Object> propertyList) { for (int i = 0; i < propertyList.size(); i++) { String name = propertyList.getName(i); String newName = mappings.inverse().get(name); if (newName != null) { propertyList.setName(i, newName); } } }
Example 16
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 17
Source File: RewriteFacetCountsComponent.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
/** * Update pivot fields in the response to reference ACS properties rather than Solr fields. * * @param rb The response builder. * @param sections The names of the sections in the response to update. */ private void rewritePivotFields(ResponseBuilder rb, String ... sections) { Map<String, String> mappings = (Map<String, String>) rb.rsp.getValues().get("_pivot_mappings_"); if(mappings != null) { NamedList<Object> found = (NamedList<Object>) rb.rsp.getValues(); for(String section : sections) { found = (NamedList<Object>)found.get(section); if(found == null) { return; } } for(int i = 0; i < found.size(); i++) { String pivotName = found.getName(i); String[] fromParts = pivotName.split(","); String mapping = mappings.get(pivotName); String[] toParts = mapping != null ? mapping.split(",") : fromParts; Collection<NamedList<Object>> current = (Collection<NamedList<Object>>)found.getVal(i); processPivot(rb, fromParts, toParts, current, 0); } } }
Example 18
Source File: DebugComponent.java From lucene-solr with Apache License 2.0 | 4 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) protected Object merge(Object source, Object dest, Set<String> exclude) { if (source == null) return dest; if (dest == null) { if (source instanceof NamedList) { dest = source instanceof SimpleOrderedMap ? new SimpleOrderedMap() : new NamedList(); } else { return source; } } else { if (dest instanceof Collection) { // merge as Set if (!(dest instanceof Set)) { dest = new LinkedHashSet<>((Collection<?>) dest); } if (source instanceof Collection) { ((Collection)dest).addAll((Collection)source); } else { ((Collection)dest).add(source); } return dest; } else if (source instanceof Number) { if (dest instanceof Number) { if (source instanceof Double || dest instanceof Double) { return ((Number)source).doubleValue() + ((Number)dest).doubleValue(); } return ((Number)source).longValue() + ((Number)dest).longValue(); } // fall through } else if (source instanceof String) { if (source.equals(dest)) { return dest; } // fall through } } if (source instanceof NamedList && dest instanceof NamedList) { NamedList<Object> tmp = new NamedList<>(); @SuppressWarnings("unchecked") NamedList<Object> sl = (NamedList<Object>)source; @SuppressWarnings("unchecked") NamedList<Object> dl = (NamedList<Object>)dest; for (int i=0; i<sl.size(); i++) { String skey = sl.getName(i); if (exclude.contains(skey)) continue; Object sval = sl.getVal(i); int didx = -1; // optimize case where elements are in same position if (i < dl.size()) { String dkey = dl.getName(i); if (skey == dkey || (skey!=null && skey.equals(dkey))) { didx = i; } } if (didx == -1) { didx = dl.indexOf(skey, 0); } if (didx == -1) { tmp.add(skey, merge(sval, null, Collections.emptySet())); } else { dl.setVal(didx, merge(sval, dl.getVal(didx), Collections.emptySet())); } } dl.addAll(tmp); return dl; } // only add to list if JSON is different if (source.equals(dest)) return source; // merge unlike elements in a list List<Object> t = new ArrayList<>(); t.add(dest); t.add(source); return t; }
Example 19
Source File: JSONResponseWriter.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void writeNamedList(String name, @SuppressWarnings({"rawtypes"})NamedList val) throws IOException { if (val instanceof SimpleOrderedMap) { super.writeNamedList(name, val); return; } final int sz = val.size(); indent(); writeArrayOpener(sz); incLevel(); boolean first = true; for (int i=0; i<sz; i++) { if (first) { first = false; } else { writeArraySeparator(); } indent(); final String elementName = val.getName(i); final Object elementVal = val.getVal(i); /* * JSONWriter's writeNamedListAsArrMap turns NamedList("bar"="foo") into [{"foo":"bar"}] * but we here wish to turn it into [ {"name":"bar","type":"str","value":"foo"} ] instead. * * So first we write the <code>{"name":"bar",</code> portion ... */ writeMapOpener(-1); if (elementName != null || writeNullName) { writeKey("name", false); writeVal("name", elementName); writeMapSeparator(); } /* * ... and then we write the <code>"type":"str","value":"foo"}</code> portion. */ writeTypeAndValueKey = true; writeVal(null, elementVal); // passing null since writeVal doesn't actually use name (and we already wrote elementName above) if (writeTypeAndValueKey) { throw new RuntimeException("writeTypeAndValueKey should have been reset to false by writeVal('"+elementName+"','"+elementVal+"')"); } writeMapCloser(); } decLevel(); writeArrayCloser(); }
Example 20
Source File: QueryResponse.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings({"rawtypes"}) public void setResponse( NamedList<Object> res ) { super.setResponse( res ); // Look for known things for( int i=0; i<res.size(); i++ ) { String n = res.getName( i ); if( "responseHeader".equals( n ) ) { _header = (NamedList<Object>) res.getVal( i ); } else if( "response".equals( n ) ) { _results = (SolrDocumentList) res.getVal( i ); } else if( "sort_values".equals( n ) ) { _sortvalues = (NamedList<ArrayList>) res.getVal( i ); } else if( "facet_counts".equals( n ) ) { _facetInfo = (NamedList<Object>) res.getVal( i ); // extractFacetInfo inspects _results, so defer calling it // in case it hasn't been populated yet. } else if( "debug".equals( n ) ) { _debugInfo = (NamedList<Object>) res.getVal( i ); extractDebugInfo( _debugInfo ); } else if( "grouped".equals( n ) ) { _groupedInfo = (NamedList<Object>) res.getVal( i ); extractGroupedInfo( _groupedInfo ); } else if("expanded".equals(n)) { NamedList map = (NamedList) res.getVal(i); _expandedResults = map.asMap(1); } else if( "highlighting".equals( n ) ) { _highlightingInfo = (NamedList<Object>) res.getVal( i ); extractHighlightingInfo( _highlightingInfo ); } else if ( "spellcheck".equals( n ) ) { _spellInfo = (NamedList<Object>) res.getVal( i ); extractSpellCheckInfo( _spellInfo ); } else if ("clusters".equals(n)) { _clusterInfo = (ArrayList<NamedList<Object>>) res.getVal(i); extractClusteringInfo(_clusterInfo); } else if ("facets".equals(n)) { _jsonFacetingInfo = (NamedList<Object>) res.getVal(i); // Don't call extractJsonFacetingInfo(_jsonFacetingInfo) here in an effort to do it lazily } else if ( "suggest".equals( n ) ) { _suggestInfo = (Map<String,NamedList<Object>>) res.getVal( i ); extractSuggesterInfo(_suggestInfo); } else if ( "stats".equals( n ) ) { _statsInfo = (NamedList<Object>) res.getVal( i ); extractStatsInfo( _statsInfo ); } else if ( "terms".equals( n ) ) { _termsInfo = (NamedList<NamedList<Object>>) res.getVal( i ); extractTermsInfo( _termsInfo ); } else if ( "moreLikeThis".equals( n ) ) { _moreLikeThisInfo = (NamedList<SolrDocumentList>) res.getVal( i ); } else if ( CursorMarkParams.CURSOR_MARK_NEXT.equals( n ) ) { _cursorMarkNext = (String) res.getVal( i ); } } if(_facetInfo != null) extractFacetInfo( _facetInfo ); }