protected Map<String, Map<String, Long>> getFacetCounts(List<String> fields, QueryResponse solrResponse) { Map<String, Map<String, Long>> fieldCounts = new HashMap<>(); for (String field : fields) { Map<String, Long> valueCounts = new HashMap<>(); FacetField facetField = solrResponse.getFacetField(field); for (Count facetCount : facetField.getValues()) { valueCounts.put(facetCount.getName(), facetCount.getCount()); } fieldCounts.put(field, valueCounts); } return fieldCounts; }
FacetField facetField = resp.getFacetField("facet_" + facet.getField());
FacetField facetField = resp.getFacetField("facet_" + facet.getField());
/** * Delegator.<p> * * @param name the name * * @return the facet field */ public FacetField getFacetField(String name) { return m_queryResponse.getFacetField(name); }
public static void main() { String url = "http://localhost:8983/solr/autocomplete"; SolrServer solrServer = new HttpSolrServer(url); SolrQuery query = new SolrQuery(); query.set("q", "*"); query.addFilterQuery("name:*"); query.setFacet(true); query.addFacetField("name"); System.out.println(query); QueryResponse queryResponse = solrServer.query(query); List<FacetField> facetFields = queryResponse.getFacetFields(); FacetField cnameMainFacetField = queryResponse.getFacetField("name"); for (Count cnameAndCount : cnameMainFacetField.getValues()) { String cnameMain = cnameAndCount.getName(); System.out.println(cnameMain); System.out.println(cnameAndCount.getCount()); }
@Override public Iterator<Node> listGraphNodes() { try { final QueryResponse response = cloud.query(LIST_GRAPHS_QUERY); final FacetField graphFacetField = response.getFacetField(Field.C); if (graphFacetField != null && graphFacetField.getValueCount() > 0) { final List<Node> graphs = new ArrayList<Node>(); for (final FacetField.Count graphName : graphFacetField.getValues()) { graphs.add(NTriples.asURI(graphName.getName())); } return graphs.iterator(); } return EMPTY_GRAPHS_ITERATOR; } catch (final Exception exception) { LOGGER.error(MessageCatalog._00113_NWS_FAILURE, exception); throw new SolrException(ErrorCode.SERVER_ERROR, exception); } }
solrQueryResponse.setDvObjectCounts(queryResponse.getFacetField("dvObjectType")); solrQueryResponse.setPublicationStatusCounts(queryResponse.getFacetField("publicationStatus"));
public Multimap<String,InteractorIdCount> searchInteractors(SolrQuery originalQuery, String[] interactorTypeMis) throws IntactSolrException { SolrQuery query = originalQuery.getCopy(); query.setRows(0); query.setFacet(true); query.setFacetMinCount(1); query.setFacetLimit(Integer.MAX_VALUE); query.setFacetSort(FacetParams.FACET_SORT_COUNT); Multimap<String,InteractorIdCount> interactors = HashMultimap.create(); Map<String,String> fieldNameToTypeMap = new HashMap<String,String>(interactorTypeMis.length); for (String mi : interactorTypeMis) { final String fieldName = createFieldName(mi); query.addFacetField(fieldName); fieldNameToTypeMap.put(fieldName, mi); } QueryResponse queryResponse = executeQuery(query); for (Map.Entry<String,String> entry : fieldNameToTypeMap.entrySet()) { FacetField ff = queryResponse.getFacetField(entry.getKey()); if (ff != null && ff.getValues() != null) { for (FacetField.Count c : ff.getValues()) { interactors.put(entry.getValue(), new InteractorIdCount(c.getName(), c.getCount())); } } } return interactors; }
public Set<String> getOntologyNames() throws SolrServerException { if (ontologyNames == null) { SolrQuery query = new SolrQuery("*:*"); query.setStart(0); query.setRows(0); query.setFacet(true); query.setParam(FacetParams.FACET_FIELD, "ontology"); QueryResponse response = search(query); FacetField facetField = response.getFacetField("ontology"); if (facetField.getValues() == null) { return Collections.EMPTY_SET; } ontologyNames = new HashSet<String>( facetField.getValues().size() ); for (FacetField.Count c : facetField.getValues()) { ontologyNames.add(c.getName()); } } return ontologyNames; }
/** * Retrieves all the metadata fields which are indexed in the authority control * * @return a list of metadata fields * @throws Exception if error */ @Override public List<String> getAllIndexedMetadataFields() throws Exception { SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery("*:*"); solrQuery.setFacet(true); solrQuery.addFacetField("field"); QueryResponse response = getSolr().query(solrQuery); List<String> results = new ArrayList<String>(); FacetField facetField = response.getFacetField("field"); if (facetField != null) { List<FacetField.Count> values = facetField.getValues(); if (values != null) { for (FacetField.Count facetValue : values) { if (facetValue != null && facetValue.getName() != null) { results.add(facetValue.getName()); } } } } return results; } }
public static <T extends IsIndexed> List<String> suggest(SolrClient index, Class<T> classToRetrieve, String field, String queryString, boolean justActive, User user, boolean allowPartial) throws GenericException { StringBuilder queryBuilder = new StringBuilder(); appendKeyValue(queryBuilder, field + RodaConstants.INDEX_SEARCH_SUFFIX, queryString + "*"); SolrQuery query = new SolrQuery(); query.setParam("q.op", DEFAULT_QUERY_PARSER_OPERATOR); query.setQuery(queryBuilder.toString()); if (hasPermissionFilters(classToRetrieve)) { query.addFilterQuery(getFilterQueries(user, justActive, classToRetrieve)); } parseAndConfigureFacets(new Facets(new SimpleFacetParameter(field)), query); List<String> suggestions = new ArrayList<>(); try { QueryResponse response = index.query(SolrCollectionRegistry.getIndexName(classToRetrieve), query); response.getFacetField(field).getValues().forEach(count -> suggestions.add(count.getName())); } catch (SolrServerException | IOException | SolrException | NotSupportedException e) { throw new GenericException("Could not get suggestions", e); } catch (RuntimeException e) { throw new GenericException("Unexpected exception while querying index", e); } return suggestions; }
if (queryresponse.getFacetField(facetField) != null) { fieldsList = queryresponse.getFacetField(facetField).getValues();
public Set<String> getOntologyNames() throws SolrServerException { if (ontologyNames == null) { SolrQuery query = new SolrQuery("*:*"); query.setStart(0); query.setRows(0); // prepare faceting query.setFacet(true); query.setParam(FacetParams.FACET_FIELD, "ontology"); query.setFacetLimit(10); query.setFacetMinCount(1); query.set(FacetParams.FACET_OFFSET, 0); // order by unique id query.addSortField(OntologyFieldNames.ID, SolrQuery.ORDER.asc); QueryResponse response = search(query, null); FacetField facetField = response.getFacetField("ontology"); if (facetField.getValues() == null) { return Collections.EMPTY_SET; } ontologyNames = new HashSet<String>( facetField.getValues().size() ); for (FacetField.Count c : facetField.getValues()) { ontologyNames.add(c.getName()); } } return ontologyNames; }
FacetField field = queryResponse.getFacetField(facetField);
FacetField field = queryResponse.getFacetField(facetField);