/** * Subclass can override to customize per-dim Facets * impl. */ protected Facets buildFacetsResult(FacetsCollector drillDowns, FacetsCollector[] drillSideways, String[] drillSidewaysDims) throws IOException { Facets drillDownFacets; Map<String, Facets> drillSidewaysFacets = new HashMap<>(); if (taxoReader != null) { drillDownFacets = new FastTaxonomyFacetCounts(taxoReader, config, drillDowns); if (drillSideways != null) { for (int i = 0; i < drillSideways.length; i++) { drillSidewaysFacets.put(drillSidewaysDims[i], new FastTaxonomyFacetCounts(taxoReader, config, drillSideways[i])); } } } else { drillDownFacets = new SortedSetDocValuesFacetCounts(state, drillDowns); if (drillSideways != null) { for (int i = 0; i < drillSideways.length; i++) { drillSidewaysFacets.put(drillSidewaysDims[i], new SortedSetDocValuesFacetCounts(state, drillSideways[i])); } } } if (drillSidewaysFacets.isEmpty()) { return drillDownFacets; } else { return new MultiFacets(drillSidewaysFacets, drillDownFacets); } }
private FacetResult getTopChildren0(int topN, String dim, String... path) throws IOException { FacetResult topChildren = super.getTopChildren(topN, dim, path); if (topChildren == null) { return null; } InaccessibleFacetCountManager inaccessibleFacetCountManager = new InaccessibleFacetCountManager(dim, reader, filter, state, facetsCollector, topChildren.labelValues); inaccessibleFacetCountManager.filterFacets(); LabelAndValue[] labelAndValues = inaccessibleFacetCountManager.updateLabelAndValue(); int childCount = labelAndValues.length; Number value = 0; for (LabelAndValue lv : labelAndValues) { value = value.longValue() + lv.value.longValue(); } return new FacetResult(dim, path, value, labelAndValues, childCount); }
/** Counts all facet dimensions across the provided hits. */ public SortedSetDocValuesFacetCounts(SortedSetDocValuesReaderState state, FacetsCollector hits) throws IOException { this.state = state; this.field = state.getField(); dv = state.getDocValues(); counts = new int[state.getSize()]; if (hits == null) { // browse only countAll(); } else { count(hits.getMatchingDocs()); } }
SortedSetDocValuesFacetCounts facetCounts = new SortedSetDocValuesFacetCounts( docValuesReaderState, try { facetResult = facetCounts.getTopChildren( maxFacetCount, facetRequest.getFieldName() );
@Override public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException { if (topN <= 0) { throw new IllegalArgumentException("topN must be > 0 (got: " + topN + ")"); } if (path.length > 0) { throw new IllegalArgumentException("path should be 0 length"); } OrdRange ordRange = state.getOrdRange(dim); if (ordRange == null) { throw new IllegalArgumentException("dimension \"" + dim + "\" was not indexed"); } return getDim(dim, ordRange, topN); }
/** Sparse faceting: returns any dimension that had any * hits, topCount labels per dimension. */ public SortedSetDocValuesFacetCounts(SortedSetDocValuesReaderState state, FacetsCollector hits) throws IOException { this.state = state; this.field = state.getField(); dv = state.getDocValues(); counts = new int[state.getSize()]; //System.out.println("field=" + field); count(hits.getMatchingDocs()); }
SortedSetDocValuesFacetCounts facetCounts = new SortedSetDocValuesFacetCounts( docValuesReaderState, facetsCollector ); try { facetResult = facetCounts.getTopChildren( maxFacetCount, facetRequest.getFieldName() );
@Override public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException { if (topN <= 0) { throw new IllegalArgumentException("topN must be > 0 (got: " + topN + ")"); } if (path.length > 0) { throw new IllegalArgumentException("path should be 0 length"); } OrdRange ordRange = state.getOrdRange(dim); if (ordRange == null) { throw new IllegalArgumentException("dimension \"" + dim + "\" was not indexed"); } return getDim(dim, ordRange, topN); }
/** Subclass can override to customize per-dim Facets * impl. */ protected Facets buildFacetsResult(FacetsCollector drillDowns, FacetsCollector[] drillSideways, String[] drillSidewaysDims) throws IOException { Facets drillDownFacets; Map<String,Facets> drillSidewaysFacets = new HashMap<>(); if (taxoReader != null) { drillDownFacets = new FastTaxonomyFacetCounts(taxoReader, config, drillDowns); if (drillSideways != null) { for(int i=0;i<drillSideways.length;i++) { drillSidewaysFacets.put(drillSidewaysDims[i], new FastTaxonomyFacetCounts(taxoReader, config, drillSideways[i])); } } } else { drillDownFacets = new SortedSetDocValuesFacetCounts(state, drillDowns); if (drillSideways != null) { for(int i=0;i<drillSideways.length;i++) { drillSidewaysFacets.put(drillSidewaysDims[i], new SortedSetDocValuesFacetCounts(state, drillSideways[i])); } } } if (drillSidewaysFacets.isEmpty()) { return drillDownFacets; } else { return new MultiFacets(drillSidewaysFacets, drillDownFacets); } }
private FacetResult getTopChildren0(int topN, String dim, String... path) throws IOException { FacetResult topChildren = super.getTopChildren(topN, dim, path); if (topChildren == null) { return null; } InaccessibleFacetCountManager inaccessibleFacetCountManager = new InaccessibleFacetCountManager(dim, reader, filter, state, facetsCollector, topChildren.labelValues); inaccessibleFacetCountManager.filterFacets(); LabelAndValue[] labelAndValues = inaccessibleFacetCountManager.updateLabelAndValue(); int childCount = labelAndValues.length; Number value = 0; for (LabelAndValue lv : labelAndValues) { value = value.longValue() + lv.value.longValue(); } return new FacetResult(dim, path, value, labelAndValues, childCount); }
@Override public List<FacetResult> getAllDims(int topN) throws IOException { List<FacetResult> results = new ArrayList<>(); for(Map.Entry<String,OrdRange> ent : state.getPrefixToOrdRange().entrySet()) { FacetResult fr = getDim(ent.getKey(), ent.getValue(), topN); if (fr != null) { results.add(fr); } } // Sort by highest count: Collections.sort(results, new Comparator<FacetResult>() { @Override public int compare(FacetResult a, FacetResult b) { if (a.value.intValue() > b.value.intValue()) { return -1; } else if (b.value.intValue() > a.value.intValue()) { return 1; } else { return a.dim.compareTo(b.dim); } } }); return results; } }
protected Facets buildFacetsResult(final FacetsCollector drillDowns, final FacetsCollector[] drillSideways, final String[] drillSidewaysDims) throws IOException { final Map<String, Facets> drillSidewaysFacets = new HashMap<>(); final FastTaxonomyFacetCounts fastTaxonomyFacets = taxoReader == null ? null : new FastTaxonomyFacetCounts( taxoReader, config, drillDowns); final SortedSetDocValuesFacetCounts docValuesFacets = state == null ? null : new SortedSetDocValuesFacetCounts( state, drillDowns); if (drillSideways != null) { for (int i = 0; i < drillSideways.length; i++) { final String dim = drillSidewaysDims[i]; final Facets facets; final String indexFieldName = config.getDimConfig(dim).indexFieldName; if (state != null && stateIndexField.equals(indexFieldName)) { facets = new SortedSetDocValuesFacetCounts(state, drillSideways[i]); } else if (taxoReader != null) { facets = new FastTaxonomyFacetCounts(taxoReader, config, drillSideways[i]); } else facets = null; if (facets != null) drillSidewaysFacets.put(dim, facets); } } final Facets facets = new MixedFacets(docValuesFacets, fastTaxonomyFacets); return drillSidewaysFacets.isEmpty() ? facets : new MultiFacets(drillSidewaysFacets, facets); }
private FacetResult getTopChildren0(int topN, String dim, String... path) throws IOException { FacetResult topChildren = super.getTopChildren(topN, dim, path);
@Override public List<FacetResult> getAllDims(int topN) throws IOException { List<FacetResult> results = new ArrayList<>(); for(Map.Entry<String,OrdRange> ent : state.getPrefixToOrdRange().entrySet()) { FacetResult fr = getDim(ent.getKey(), ent.getValue(), topN); if (fr != null) { results.add(fr); } } // Sort by highest count: Collections.sort(results, new Comparator<FacetResult>() { @Override public int compare(FacetResult a, FacetResult b) { if (a.value.intValue() > b.value.intValue()) { return -1; } else if (b.value.intValue() > a.value.intValue()) { return 1; } else { return a.dim.compareTo(b.dim); } } }); return results; } }
/** User runs a query and counts facets. */ private List<FacetResult> search() throws IOException { DirectoryReader indexReader = DirectoryReader.open(indexDir); IndexSearcher searcher = new IndexSearcher(indexReader); SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(indexReader); // Aggregatses 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); // Retrieve results Facets facets = new SortedSetDocValuesFacetCounts(state, fc); List<FacetResult> results = new ArrayList<>(); results.add(facets.getTopChildren(10, "Author")); results.add(facets.getTopChildren(10, "Publish Year")); indexReader.close(); return results; }
private FacetResult getTopChildren0(int topN, String dim, String... path) throws IOException { FacetResult topChildren = super.getTopChildren(topN, dim, path);
/** 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; }
WithCollectors(final QueryContextImpl queryContext, final FacetsConfig facetsConfig, final LinkedHashMap<String, FacetDefinition> facetsDef, final Query searchQuery, final TimeTracker timeTracker, final FacetsCollector facetsCollector) throws IOException, ParseException, ReflectiveOperationException, QueryNodeException { super(queryContext, facetsDef, searchQuery, timeTracker); this.facetsConfig = facetsConfig; int facetFlag = checkFacetTypeFlags(facetsConfig, facetsDef); this.sortedSetCounts = queryContext.docValueReaderState == null ? null : (facetFlag & FACET_IS_SORTED) == FACET_IS_SORTED ? new SortedSetDocValuesFacetCounts(queryContext.docValueReaderState, facetsCollector) : null; this.taxonomyCounts = (facetFlag & FACET_IS_TAXO) == FACET_IS_TAXO ? new FastTaxonomyFacetCounts(queryContext.taxonomyReader, facetsConfig, facetsCollector) : null; this.floatTaxonomyCounts = (facetFlag & FACET_IS_TAXO_FLOAT) == FACET_IS_TAXO_FLOAT ? new TaxonomyFacetSumFloatAssociations(FieldDefinition.TAXONOMY_FLOAT_ASSOC_FACET_FIELD, queryContext.taxonomyReader, facetsConfig, facetsCollector) : null; this.intTaxonomyCounts = (facetFlag & FACET_IS_TAXO_INT) == FACET_IS_TAXO_INT ? new TaxonomyFacetSumIntAssociations(FieldDefinition.TAXONOMY_INT_ASSOC_FACET_FIELD, queryContext.taxonomyReader, facetsConfig, facetsCollector) : null; }
facets = new SortedSetDocValuesFacetCounts(state, facetsCollector); break; case STATISTICAL:
facets = new SortedSetDocValuesFacetCounts(state, facetsCollector); break; case STATISTICAL: