@Override public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException { Facets facets = dimToFacets.get(dim); if (facets == null) { if (defaultFacets == null) { throw new IllegalArgumentException("invalid dim \"" + dim + "\""); } facets = defaultFacets; } return facets.getTopChildren(topN, dim, path); }
@Override public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException { Facets facets = dimToFacets.get(dim); if (facets == null) { if (defaultFacets == null) { throw new IllegalArgumentException("invalid dim \"" + dim + "\""); } facets = defaultFacets; } return facets.getTopChildren(topN, dim, path); }
public static String getFacetResultChildDisplayLabel(Facets facets, FacetResult facetResult, LabelAndValue labelAndValue) throws IOException { String path[] = Arrays.copyOf(facetResult.path, facetResult.path.length + 1); path[path.length - 1] = labelAndValue.label; FacetResult subResult = facets.getTopChildren(1 /* topN */, facetResult.dim, path); if (subResult != null && subResult.childCount > 0) { return StringUtils.capitalize(subResult.labelValues[0].label); } else { return StringUtils.capitalize(labelAndValue.label); } }
@Override public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException { final Facets facets = getFacets(dim); return facets == null ? null : facets.getTopChildren(topN, dim, path); }
@Override public List<FacetResult> getAllDims(int topN) throws IOException { List<FacetResult> results = new ArrayList<FacetResult>(); // First add the specific dim's facets: for(Map.Entry<String,Facets> ent : dimToFacets.entrySet()) { results.add(ent.getValue().getTopChildren(topN, ent.getKey())); } if (defaultFacets != null) { // Then add all default facets as long as we didn't // already add that dim: for(FacetResult result : defaultFacets.getAllDims(topN)) { if (dimToFacets.containsKey(result.dim) == false) { results.add(result); } } } return results; } }
@Override public List<FacetResult> getAllDims(int topN) throws IOException { List<FacetResult> results = new ArrayList<FacetResult>(); // First add the specific dim's facets: for(Map.Entry<String,Facets> ent : dimToFacets.entrySet()) { results.add(ent.getValue().getTopChildren(topN, ent.getKey())); } if (defaultFacets != null) { // Then add all default facets as long as we didn't // already add that dim: for(FacetResult result : defaultFacets.getAllDims(topN)) { if (dimToFacets.containsKey(result.dim) == false) { results.add(result); } } } return results; } }
public static String getFacetPathDisplayLabel(Facets facets, RcIrFacetPath facetPath) throws IOException { FacetResult facetResult = facets.getTopChildren(1 /* topN */, facetPath.getDimension(), facetPath.getPath()); if (facetResult != null && facetResult.childCount > 0) { return StringUtils.capitalize(facetResult.labelValues[0].label); } else { return StringUtils.capitalize(facetPath.components[facetPath.components.length - 1]); } }
@Override public List<Facet> getFacets(int numberOfFacets, String columnName) throws IOException { String facetFieldName = FulltextIndex.parseFacetField(columnName); if (facets != null) { ImmutableList.Builder res = new ImmutableList.Builder<Facet>(); FacetResult topChildren = facets.getTopChildren(numberOfFacets, facetFieldName); if (topChildren != null) { for (LabelAndValue lav : topChildren.labelValues) { res.add(new Facet( lav.label, lav.value.intValue() )); } return res.build(); } } return null; } }
@Override public List<Facet> getFacets(int numberOfFacets, String columnName) throws IOException { String facetFieldName = FulltextIndex.parseFacetField(columnName); if (facets != null) { ImmutableList.Builder res = new ImmutableList.Builder<Facet>(); FacetResult topChildren = facets.getTopChildren(numberOfFacets, facetFieldName); if (topChildren != null) { for (LabelAndValue lav : topChildren.labelValues) { res.add(new Facet( lav.label, lav.value.intValue() )); } return res.build(); } } return null; } }
/** User runs a query and counts facets only without collecting the matching documents.*/ private List<FacetResult> facetsOnly() throws IOException { DirectoryReader indexReader = DirectoryReader.open(indexDir); IndexSearcher searcher = new IndexSearcher(indexReader); TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir); FacetsCollector fc = new FacetsCollector(); // MatchAllDocsQuery is for "browsing" (counts facets // for all non-deleted docs in the index); normally // you'd use a "normal" query: searcher.search(new MatchAllDocsQuery(), fc); // Retrieve results List<FacetResult> results = new ArrayList<>(); // Count both "Publish Date" and "Author" dimensions Facets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc); results.add(facets.getTopChildren(10, "Author")); results.add(facets.getTopChildren(10, "Publish Date")); indexReader.close(); taxoReader.close(); return results; }
private CategoryDrillDownResponse getCategoryDrillDownResponse( CategoryDrillDownRequest drillDownRequest, List<CategorySearchResultEntry> searchResults, String[] path, Facets facets) throws IOException { FacetResult facetResult = facets.getTopChildren(Integer.MAX_VALUE, drillDownRequest.getFieldName(), path); CategoryDrillDownResponse response; if (facetResult != null) { LabelAndValue[] categories = facetResult.labelValues; for (LabelAndValue category : categories) { searchResults.add(new CategorySearchResultEntry(category.label, category.value.doubleValue())); } response = new CategoryDrillDownResponse(searchResults); } else { response = new CategoryDrillDownResponse(new ArrayList<CategorySearchResultEntry>(0)); } return response; }
/** User runs a query and counts facets. */ private List<FacetResult> facetsWithSearch() throws IOException { DirectoryReader indexReader = DirectoryReader.open(indexDir); IndexSearcher searcher = new IndexSearcher(indexReader); TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir); FacetsCollector fc = new FacetsCollector(); // MatchAllDocsQuery is for "browsing" (counts facets // for all non-deleted docs in the index); normally // you'd use a "normal" query: FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc); // Retrieve results List<FacetResult> results = new ArrayList<>(); // Count both "Publish Date" and "Author" dimensions Facets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc); results.add(facets.getTopChildren(10, "Author")); results.add(facets.getTopChildren(10, "Publish Date")); indexReader.close(); taxoReader.close(); return results; }
/** User runs a query and aggregates facets by summing their association values. */ private List<FacetResult> sumAssociations() throws IOException { DirectoryReader indexReader = DirectoryReader.open(indexDir); IndexSearcher searcher = new IndexSearcher(indexReader); TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir); FacetsCollector fc = new FacetsCollector(); // MatchAllDocsQuery is for "browsing" (counts facets // for all non-deleted docs in the index); normally // you'd use a "normal" query: FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc); Facets tags = new TaxonomyFacetSumIntAssociations("$tags", taxoReader, config, fc); Facets genre = new TaxonomyFacetSumFloatAssociations("$genre", taxoReader, config, fc); // Retrieve results List<FacetResult> results = new ArrayList<>(); results.add(tags.getTopChildren(10, "tags")); results.add(genre.getTopChildren(10, "genre")); indexReader.close(); taxoReader.close(); return results; }
/** User runs a query and counts facets. */ public FacetResult search() throws IOException { FacetsCollector fc = new FacetsCollector(); searcher.search(new MatchAllDocsQuery(), fc); Facets facets = new DoubleRangeFacetCounts("field", getDistanceValueSource(), fc, getBoundingBoxQuery(ORIGIN_LATITUDE, ORIGIN_LONGITUDE, 10.0), ONE_KM, TWO_KM, FIVE_KM, TEN_KM); return facets.getTopChildren(10, "field"); }
/** User runs a query and counts facets. */ public FacetResult search() throws IOException { // Aggregates the facet counts FacetsCollector fc = new FacetsCollector(); // MatchAllDocsQuery is for "browsing" (counts facets // for all non-deleted docs in the index); normally // you'd use a "normal" query: FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc); Facets facets = new LongRangeFacetCounts("timestamp", fc, PAST_HOUR, PAST_SIX_HOURS, PAST_DAY); return facets.getTopChildren(10, "timestamp"); }
/** User drills down on 'Publish Year/2010'. */ private FacetResult drillDown() throws IOException { DirectoryReader indexReader = DirectoryReader.open(indexDir); IndexSearcher searcher = new IndexSearcher(indexReader); SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(indexReader); // Now user drills down on Publish Year/2010: DrillDownQuery q = new DrillDownQuery(config); q.add("Publish Year", "2010"); FacetsCollector fc = new FacetsCollector(); FacetsCollector.search(searcher, q, 10, fc); // Retrieve results Facets facets = new SortedSetDocValuesFacetCounts(state, fc); FacetResult result = facets.getTopChildren(10, "Author"); indexReader.close(); return result; }
private void buildFacetState(final String resolvedDimension, final Integer top, final Set<String[]> specificValues, final FacetBuilder facetBuilder) throws IOException { final Facets facets = getFacets(resolvedDimension); if (facets == null) return; if (top != null && top > 0) { final FacetResult facetResult = facets.getTopChildren(top, resolvedDimension); if (facetResult != null && facetResult.labelValues != null) for (LabelAndValue lv : facetResult.labelValues) facetBuilder.put(lv); } if (specificValues != null) { for (String[] path : specificValues) { final Number count = facets.getSpecificValue(resolvedDimension, path); facetBuilder.put(new LabelAndValue(StringUtils.join(path, '/'), count == null || count.longValue() <= 0 ? 0 : count)); } } }
/** User drills down on 'tags/solr'. */ private FacetResult drillDown() throws IOException { DirectoryReader indexReader = DirectoryReader.open(indexDir); IndexSearcher searcher = new IndexSearcher(indexReader); TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir); // Passing no baseQuery means we drill down on all // documents ("browse only"): DrillDownQuery q = new DrillDownQuery(config); // Now user drills down on Publish Date/2010: q.add("tags", "solr"); FacetsCollector fc = new FacetsCollector(); FacetsCollector.search(searcher, q, 10, fc); // Retrieve results Facets facets = new TaxonomyFacetSumFloatAssociations("$genre", taxoReader, config, fc); FacetResult result = facets.getTopChildren(10, "genre"); indexReader.close(); taxoReader.close(); return result; }
/** User drills down on 'Publish Date/2010', and we * return facets for 'Author' */ private FacetResult drillDown() throws IOException { DirectoryReader indexReader = DirectoryReader.open(indexDir); IndexSearcher searcher = new IndexSearcher(indexReader); TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir); // Passing no baseQuery means we drill down on all // documents ("browse only"): DrillDownQuery q = new DrillDownQuery(config); // Now user drills down on Publish Date/2010: q.add("Publish Date", "2010"); FacetsCollector fc = new FacetsCollector(); FacetsCollector.search(searcher, q, 10, fc); // Retrieve results Facets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc); FacetResult result = facets.getTopChildren(10, "Author"); indexReader.close(); taxoReader.close(); return result; }
/** User drills down on 'Publish Year/2010'. */ private FacetResult drillDown() throws IOException { DirectoryReader indexReader = DirectoryReader.open(directory); IndexSearcher searcher = new IndexSearcher(indexReader); SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(indexReader); // Now user drills down on Publish Year/2010: DrillDownQuery q = new DrillDownQuery(config); q.add("Publish Year", "2010"); FacetsCollector fc = new FacetsCollector(); FacetsCollector.search(searcher, q, 10, fc); // Retrieve results Facets facets = new SortedSetDocValuesFacetCounts(state, fc); FacetResult result = facets.getTopChildren(10, "Author"); indexReader.close(); return result; }