public static Map<String,Integer> getChildCounts(SolrResponse response) { //check if there are subdocs if (Objects.nonNull(response.getResponse())) { final Object subDocumentFacetResult = response.getResponse().get("facets"); if (Objects.nonNull(subDocumentFacetResult)) { Map<String,Integer> childCounts = new HashMap<>(); log.debug("Parsing subdocument facet result from JSON "); final int facetCount = (int) ((SimpleOrderedMap) subDocumentFacetResult).get("count"); if (facetCount > 0 && Objects.nonNull(((SimpleOrderedMap) subDocumentFacetResult).get("parent_facet"))) { final List<SimpleOrderedMap> parentDocs = (ArrayList) ((SimpleOrderedMap) ((SimpleOrderedMap) subDocumentFacetResult).get("parent_facet")).get("buckets"); childCounts = parentDocs.stream().collect(Collectors.toMap(p -> (String) p.get("val"), p -> ((Integer) ((SimpleOrderedMap) p.get("children_facet")).get("count")))); } return childCounts; } } return null; }
private static TermFacetResult<String> getTypeFacetResults(QueryResponse response) { final TermFacetResult typeFacetResults = new TermFacetResult(); //term facets if (Objects.nonNull(response.getResponse())) { final SimpleOrderedMap jsonFacetResult = (SimpleOrderedMap) response.getResponse().get("facets"); if (Objects.nonNull(jsonFacetResult)) { for (int i = 0; i < jsonFacetResult.size(); i++) { if (jsonFacetResult.getName(i).equals(Fieldname.TYPE)) { final ArrayList<SimpleOrderedMap> termFacet = ((ArrayList<SimpleOrderedMap>) ((SimpleOrderedMap) jsonFacetResult.get(jsonFacetResult.getName(i))).get("buckets")); termFacet.stream().forEach(f -> typeFacetResults .addFacetValue(new FacetValue<>((String) f.get("val"), ((Integer)f.get("count")).longValue()))); } } } } return typeFacetResults; }
public SuggesterResponse(Map<String, NamedList<Object>> suggestInfo) { for (Map.Entry<String, NamedList<Object>> entry : suggestInfo.entrySet()) { SimpleOrderedMap suggestionsNode = (SimpleOrderedMap) entry.getValue().getVal(0); List<SimpleOrderedMap> suggestionListToParse; List<Suggestion> suggestionList = new LinkedList<>(); if (suggestionsNode != null) { suggestionListToParse = (List<SimpleOrderedMap>) suggestionsNode.get(SUGGESTIONS_NODE_NAME); for (SimpleOrderedMap suggestion : suggestionListToParse) { String term = (String) suggestion.get(TERM_NODE_NAME); long weight = (long) suggestion.get(WEIGHT_NODE_NAME); String payload = (String) suggestion.get(PAYLOAD_NODE_NAME); Suggestion parsedSuggestion = new Suggestion(term, weight, payload); suggestionList.add(parsedSuggestion); } suggestionsPerDictionary.put(entry.getKey(), suggestionList); } } }
public SuggesterResponse(Map<String, NamedList<Object>> suggestInfo) { for (Map.Entry<String, NamedList<Object>> entry : suggestInfo.entrySet()) { SimpleOrderedMap suggestionsNode = (SimpleOrderedMap) entry.getValue().getVal(0); List<SimpleOrderedMap> suggestionListToParse; List<Suggestion> suggestionList = new LinkedList<>(); if (suggestionsNode != null) { suggestionListToParse = (List<SimpleOrderedMap>) suggestionsNode.get(SUGGESTIONS_NODE_NAME); for (SimpleOrderedMap suggestion : suggestionListToParse) { String term = (String) suggestion.get(TERM_NODE_NAME); long weight = (long) suggestion.get(WEIGHT_NODE_NAME); String payload = (String) suggestion.get(PAYLOAD_NODE_NAME); Suggestion parsedSuggestion = new Suggestion(term, weight, payload); suggestionList.add(parsedSuggestion); } suggestionsPerDictionary.put(entry.getKey(), suggestionList); } } }
public static Map<Integer,Integer> getSubdocumentCounts(SolrResponse response) { //check if there are subdocs if (Objects.nonNull(response.getResponse())) { final Object subDocumentFacetResult = response.getResponse().get("facets"); if (Objects.nonNull(subDocumentFacetResult)) { Map<Integer,Integer> childCounts = new HashMap<>(); log.debug("Parsing subdocument facet result from JSON "); final int facetCount = (int) ((SimpleOrderedMap) subDocumentFacetResult).get("count"); if (facetCount > 0 && Objects.nonNull(((SimpleOrderedMap) subDocumentFacetResult).get("childrenCount"))) { final SimpleOrderedMap parentDocs = ((SimpleOrderedMap) ((SimpleOrderedMap) subDocumentFacetResult).get("childrenCount")); final Integer childCount = (Integer) parentDocs.get("count"); final Integer parentCount; if(childCount > 0) { parentCount =(Integer)((SimpleOrderedMap)((List)((SimpleOrderedMap)parentDocs.get("parentFilteredCount")).get("buckets")).get(0)).get("count"); } else { parentCount = 0; } childCounts.put(parentCount, childCount); } return childCounts; } } return null; }
/** * returns a ToleratedUpdateError instance from the data in this Map * @see #getSimpleMap */ public static ToleratedUpdateError parseMap(SimpleOrderedMap<String> data) { final String id = data.get(ID); final String message = data.get("message"); final String t = data.get("type"); if (null == t || null == id || null == message) { throw new SolrException(ErrorCode.SERVER_ERROR, "Map does not represent a ToleratedUpdateError, must contain 'type', 'id', and 'message'"); } try { return new ToleratedUpdateError(CmdType.valueOf(t), id, message); } catch (IllegalArgumentException iae) { throw new SolrException(ErrorCode.SERVER_ERROR, "Invalid type for ToleratedUpdateError: " + t, iae); } }
if (next.getKey().startsWith(SolrQueryParser.CHROM_DENSITY)) { SimpleOrderedMap value = next.getValue(); if (value.get("chromosome") != null) { List<SimpleOrderedMap<Object>> chromBuckets = (List<SimpleOrderedMap<Object>>) ((SimpleOrderedMap) value.get("chromosome")).get("buckets"); for (SimpleOrderedMap<Object> chromBucket: chromBuckets) { String chrom = chromBucket.get("val").toString(); SimpleOrderedMap startMap = (SimpleOrderedMap) chromBucket.get("start"); if (startMap != null) { List<SimpleOrderedMap<Object>> startBuckets = (List<SimpleOrderedMap<Object>>) startMap.get("buckets"); for (int i = startBuckets.size() - 1; i >= 0; i--) { int pos = (int) startBuckets.get(i).get("val"); if (pos > SolrQueryParser.getChromosomeMap().get(chrom)) { startBuckets.remove(i);
/** Create new subtimer with given name * * Subtimer will be started. */ public RTimer sub(String desc) { RTimer child = children.get( desc ); if( child == null ) { child = new RTimer(); children.add(desc, child); } return child; }
SuggestionResultMulti result = new SuggestionResultMulti(limit, limitType); SimpleOrderedMap facets = (SimpleOrderedMap)((SimpleOrderedMap)rsp.getValues().get("facet_counts")).get("facet_fields"); list_of_facet_lists.addLast(l); for(String field : fields) { Iterator<Map.Entry> iter = ((NamedList)facets.get(field)).iterator(); while(iter.hasNext()) { Map.Entry<String, NamedList<Object>> entry = iter.next();
/** * Extract spellchecker's collation from original response or null if there was no collation. * @param rb . * @return . */ public static String extractSpellcheckerCollation(ResponseBuilder rb) { if (rb.rsp.getValues().get("spellcheck") != null) { if (((SimpleOrderedMap) rb.rsp.getValues().get("spellcheck")).get("collations") != null) { return (String) (((NamedList) ((SimpleOrderedMap) rb.rsp.getValues().get("spellcheck")).get("collations")).get("collation")); } } return null; }
solrQuery.setParam("q", String.valueOf(suggestion.get("term"))); solrQuery.setParam("df", configuration.getCatchAllField()); solrQuery.setParam("q.op", "AND"); for (SolrDocument doc : results) { if (filter.isAccessible(String.valueOf(doc.getFieldValue(configuration.getPathField())))) { queue.add(new SolrResultRow(suggestion.get("term").toString(), Double.parseDouble(suggestion.get("weight").toString()))); break;
/** * Returns spellchecker's suggestions from original response. In case there are no suggestions, returns null. * * @param rb . * @return . */ public static NamedList extractSpellcheckerSuggestions(ResponseBuilder rb) { if (rb.rsp.getValues().get("spellcheck") == null) { return null; } return (NamedList) ((SimpleOrderedMap) rb.rsp.getValues().get("spellcheck")).get("suggestions"); }
solrQuery.setParam("q", String.valueOf(suggestion.get("term"))); solrQuery.setParam("df", configuration.getCatchAllField()); solrQuery.setParam("q.op", "AND"); for (SolrDocument doc : results) { if (filter.isAccessible(String.valueOf(doc.getFieldValue(configuration.getPathField())))) { queue.add(new SolrResultRow(suggestion.get("term").toString(), Double.parseDouble(suggestion.get("weight").toString()))); break;
.forEach(rangeFacet -> { final Object facetRangesQuery = ((SimpleOrderedMap) response.getHeader().get("params")).get("facet.range");
processor.process(l.get(i), (String) l.get(i).get("word"));
float score = ((SimpleOrderedMap<Float>) explanations.get(omimId)).get("value"); for (Object hpoId : disorder.getFieldValues("actual_symptom")) { if (allAncestors.contains(hpoId) || nphenotypes.contains(hpoId)) {
/** * Calculates the pivot facets over documents matching the given filter query. Example output: * <p> * host: h01 * pivot: * ..metric: cpu * ..metric: heap * ..pivot: * ....process: java * ....process: php * host: h02 * ..metric: cpu * ..pivot: * ....process: java * * @param dimensions the comma separated list of fields * @param fq the filter query * @return pivot table * @throws IOException iff something goes wrong */ public List<NamedList<Object>> pivot(String dimensions, Query fq) throws IOException { ModifiableSolrParams params = new ModifiableSolrParams(req.getParams()); params.set(FACET_PIVOT, split(dimensions, ',')); params.set(FACET_ZEROS, false); params.set(FACET_LIMIT, -1); params.set(FACET_PIVOT_MINCOUNT, 1); DocSet matchingDocs = req.getSearcher().getDocSet(fq); PivotFacetProcessor pivot = dependencyProvider.pivotFacetProcessor(req, rsp, matchingDocs, params); return pivot.process(new String[]{dimensions}).get(dimensions); }
private SuggestionResult[] getSuggestionResults(String query, String df, String[] singleValueFields, String[] multiValueFields, int termLimit, int limit, SuggestionRequestHandler.LimitType limitType, SuggestionRequestHandler.Type type, SuggestionRequestHandler.Strategy strategy, String suggestionField, Map<String, Map<String, Object>> intervals, SolrQueryResponse response) { final SuggestionResult[] result; if(response.getValues().get("facets") instanceof SimpleOrderedMap) { final SimpleOrderedMap facets = (SimpleOrderedMap) response.getValues().get("facets"); if((Integer) facets.get("count") > 0) { result = createResults(response, singleValueFields, multiValueFields, query, df,type,termLimit, limit, limitType, strategy,suggestionField,intervals); } else { result = null; } } else { final SolrDocumentList facets = (SolrDocumentList) response.getValues().get("facet"); if(facets.getNumFound() > 0) { result = createResults(response, singleValueFields, multiValueFields, query, df,type,termLimit, limit, limitType, strategy,suggestionField,intervals); } else { result = null; } } return result; }
@Override public String getDatabaseProductVersion() throws SQLException { // Returns the version for the first live node in the Solr cluster. SolrQuery sysQuery = new SolrQuery(); sysQuery.setRequestHandler("/admin/info/system"); CloudSolrClient cloudSolrClient = this.connection.getClient(); Set<String> liveNodes = cloudSolrClient.getZkStateReader().getClusterState().getLiveNodes(); SolrClient solrClient = null; for (String node : liveNodes) { try { String nodeURL = cloudSolrClient.getZkStateReader().getBaseUrlForNodeName(node); solrClient = new Builder(nodeURL).build(); QueryResponse rsp = solrClient.query(sysQuery); return String.valueOf(((SimpleOrderedMap) rsp.getResponse().get("lucene")).get("solr-spec-version")); } catch (SolrServerException | IOException ignore) { return ""; } finally { if (solrClient != null) { try { solrClient.close(); } catch (IOException ignore) { // Don't worry about failing to close the Solr client } } } } // If no version found just return empty string return ""; }