java.lang.Object
org.apache.lucene.facet.Facets
org.apache.lucene.facet.LongValueFacetCounts
Facets
implementation that computes counts for all unique long values, more efficiently
counting small values (0-1023) using an int array, and switching to a HashMap
for
values above 1023. Retrieve all facet counts, in value order, with getAllChildrenSortByValue()
, or get all children with no ordering requirements with getAllChildren(String, String...)
, or get the topN values sorted by count with getTopChildren(int, String, String...)
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Reusable hash entry to hold long facet value and int count. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int[]
Used for all values that are invalid input: '<' 1K.private final String
Field being counted.private LongIntHashMap
Used for all values that are >= 1K.private boolean
Whether-or-not counters have been initialized.private int
Total value count. -
Constructor Summary
ConstructorsConstructorDescriptionLongValueFacetCounts
(String field, FacetsCollector hits) CreateLongValueFacetCounts
, using either single-valuedNumericDocValues
or multi-valuedSortedNumericDocValues
from the specified field (depending on what has been indexed).LongValueFacetCounts
(String field, MultiLongValuesSource valuesSource, FacetsCollector hits) CreateLongValueFacetCounts
, using the providedMultiLongValuesSource
if non-null.LongValueFacetCounts
(String field, MultiLongValuesSource valuesSource, IndexReader reader) Counts all facet values for the providedMultiLongValuesSource
if non-null.LongValueFacetCounts
(String field, IndexReader reader) Counts all facet values for this reader.LongValueFacetCounts
(String field, LongValuesSource valueSource, FacetsCollector hits) CreateLongValueFacetCounts
, using the providedLongValuesSource
if non-null.LongValueFacetCounts
(String field, LongValuesSource valueSource, IndexReader reader) Counts all facet values for the providedLongValuesSource
if non-null. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
appendCounts
(List<LabelAndValue> labelValues) private void
count
(String field, List<FacetsCollector.MatchingDocs> matchingDocs) Counts from the field's indexed doc values.private void
count
(MultiLongValuesSource valuesSource, List<FacetsCollector.MatchingDocs> matchingDocs) Counts from the provided valuesSource.private void
count
(LongValuesSource valueSource, List<FacetsCollector.MatchingDocs> matchingDocs) Counts from the provided valueSource.private void
countAll
(IndexReader reader, String field) Count everything in the specified field.private void
countAll
(IndexReader reader, MultiLongValuesSource valueSource) Count everything in the provided valueSource.private void
countAll
(IndexReader reader, LongValuesSource valueSource) Count everything in the provided valueSource.getAllChildren
(String dim, String... path) Returns all child labels with non-zero counts under the specified path.Returns all unique values seen, sorted by value.getAllDims
(int topN) Returns topN labels for any dimension that had hits, sorted by the number of hits that dimension matched; this is used for "sparse" faceting, where many different dimensions were indexed, for example depending on the type of document.getSpecificValue
(String dim, String... path) Return the count or value for a specific path.getTopChildren
(int topN, String dim, String... path) Returns the topN child labels under the specified path.getTopChildrenSortByCount
(int topN) Deprecated.private void
increment
(long value) private void
toString()
private void
validateDimAndPathForGetChildren
(String dim, String... path) Methods inherited from class org.apache.lucene.facet.Facets
getTopDims, validateTopN
-
Field Details
-
counts
private int[] countsUsed for all values that are invalid input: '<' 1K. -
hashCounts
Used for all values that are >= 1K. -
initialized
private boolean initializedWhether-or-not counters have been initialized. -
field
Field being counted. -
totCount
private int totCountTotal value count. For single-value cases, this is the subset of hits that had a value for this field.
-
-
Constructor Details
-
LongValueFacetCounts
CreateLongValueFacetCounts
, using either single-valuedNumericDocValues
or multi-valuedSortedNumericDocValues
from the specified field (depending on what has been indexed).- Throws:
IOException
-
LongValueFacetCounts
public LongValueFacetCounts(String field, LongValuesSource valueSource, FacetsCollector hits) throws IOException CreateLongValueFacetCounts
, using the providedLongValuesSource
if non-null. IfvalueSource
is null, doc values from the providedfield
will be used.- Throws:
IOException
-
LongValueFacetCounts
public LongValueFacetCounts(String field, MultiLongValuesSource valuesSource, FacetsCollector hits) throws IOException CreateLongValueFacetCounts
, using the providedMultiLongValuesSource
if non-null. IfvaluesSource
is null, doc values from the providedfield
will be used.- Throws:
IOException
-
LongValueFacetCounts
Counts all facet values for this reader. This produces the same result as computing facets on aMatchAllDocsQuery
, but is more efficient.- Throws:
IOException
-
LongValueFacetCounts
public LongValueFacetCounts(String field, LongValuesSource valueSource, IndexReader reader) throws IOException Counts all facet values for the providedLongValuesSource
if non-null. IfvalueSource
is null, doc values from the providedfield
will be used. This produces the same result as computing facets on aMatchAllDocsQuery
, but is more efficient.- Throws:
IOException
-
LongValueFacetCounts
public LongValueFacetCounts(String field, MultiLongValuesSource valuesSource, IndexReader reader) throws IOException Counts all facet values for the providedMultiLongValuesSource
if non-null. IfvalueSource
is null, doc values from the providedfield
will be used. This produces the same result as computing facets on aMatchAllDocsQuery
, but is more efficient.- Throws:
IOException
-
-
Method Details
-
initializeCounters
private void initializeCounters() -
count
private void count(LongValuesSource valueSource, List<FacetsCollector.MatchingDocs> matchingDocs) throws IOException Counts from the provided valueSource.- Throws:
IOException
-
count
private void count(MultiLongValuesSource valuesSource, List<FacetsCollector.MatchingDocs> matchingDocs) throws IOException Counts from the provided valuesSource.- Throws:
IOException
-
count
private void count(String field, List<FacetsCollector.MatchingDocs> matchingDocs) throws IOException Counts from the field's indexed doc values.- Throws:
IOException
-
countAll
Count everything in the provided valueSource.- Throws:
IOException
-
countAll
Count everything in the provided valueSource.- Throws:
IOException
-
countAll
Count everything in the specified field.- Throws:
IOException
-
increment
private void increment(long value) -
getAllChildren
Description copied from class:Facets
Returns all child labels with non-zero counts under the specified path. Users should make no assumptions about ordering of the children. Returns null if the specified path doesn't exist or if this dimension was never seen.- Specified by:
getAllChildren
in classFacets
- Throws:
IOException
-
getTopChildren
Description copied from class:Facets
Returns the topN child labels under the specified path. Returns null if the specified path doesn't exist or if this dimension was never seen.- Specified by:
getTopChildren
in classFacets
-
getTopChildrenSortByCount
Deprecated.Please usegetTopChildren(int, String, String...)
instead for the same functionality.Returns the specified top number of facets, sorted by count. -
getAllChildrenSortByValue
Returns all unique values seen, sorted by value. This functionality is very similar togetAllChildren(String, String...)
, but it guarantees the returned values will be sorted by value (while#getAllChildren
doesn't guarantee any sort order).Note: If you don't care about the order of children returned, it may be slightly more efficient to use
getAllChildren(String, String...)
. -
appendCounts
-
validateDimAndPathForGetChildren
-
getSpecificValue
Description copied from class:Facets
Return the count or value for a specific path. Returns -1 if this path doesn't exist, else the count.- Specified by:
getSpecificValue
in classFacets
-
getAllDims
Description copied from class:Facets
Returns topN labels for any dimension that had hits, sorted by the number of hits that dimension matched; this is used for "sparse" faceting, where many different dimensions were indexed, for example depending on the type of document.- Specified by:
getAllDims
in classFacets
-
toString
-
getTopChildren(int, String, String...)
instead for the same functionality.