Package org.apache.lucene.facet

# Class StringValueFacetCounts

java.lang.Object
org.apache.lucene.facet.Facets
org.apache.lucene.facet.StringValueFacetCounts

public class StringValueFacetCounts extends Facets
Compute facet counts from a previously indexed `SortedSetDocValues` or `SortedDocValues` field. This approach will execute facet counting against the string values found in the specified field, with no assumptions on their format. Unlike `SortedSetDocValuesFacetCounts`, no assumption is made about a "dimension" path component being indexed. Because of this, the field itself is effectively treated as the "dimension", and counts for all unique string values are produced. This approach is meant to complement `LongValueFacetCounts` in that they both provide facet counting on a doc value field with no assumptions of content.

This implementation is useful if you want to dynamically count against any string doc value field without relying on `FacetField` and `FacetsConfig`. The disadvantage is that a separate field is required for each "dimension". If you want to pack multiple dimensions into the same doc values field, you probably want one of `FastTaxonomyFacetCounts` or `SortedSetDocValuesFacetCounts`.

Note that there is an added cost on every `IndexReader` open to create a new `StringDocValuesReaderState`. Also note that this class should be instantiated and used from a single thread, because it holds a thread-private instance of `SortedSetDocValues`.

WARNING: This API is experimental and might change in incompatible ways in the next release.

## Constructor Summary

Constructors
Constructor
Description
`StringValueFacetCounts(StringDocValuesReaderState state)`
Returns all facet counts for the field, same result as searching on `MatchAllDocsQuery` but faster.
`StringValueFacetCounts(StringDocValuesReaderState state, FacetsCollector facetsCollector)`
Counts facets across the provided hits.

## Method Summary

Modifier and Type
Method
Description
`FacetResult`
`getAllChildren(String dim, String... path)`
Returns all child labels with non-zero counts under the specified path.
`List<FacetResult>`
`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.
`Number`
`getSpecificValue(String dim, String... path)`
Return the count or value for a specific path.
`FacetResult`
`getTopChildren(int topN, String dim, String... path)`
Returns the topN child labels under the specified path.

### Methods inherited from class org.apache.lucene.facet.Facets

`getTopDims, validateTopN`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### StringValueFacetCounts

public StringValueFacetCounts(StringDocValuesReaderState state) throws IOException
Returns all facet counts for the field, same result as searching on `MatchAllDocsQuery` but faster.

Throws:
  `IOException`

### StringValueFacetCounts

public StringValueFacetCounts(StringDocValuesReaderState state, FacetsCollector facetsCollector) throws IOException
Counts facets across the provided hits.

Throws:
  `IOException`

## Method Details

### getAllChildren

public FacetResult getAllChildren(String dim, String... path) throws IOException
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 class `Facets`
Throws:
  `IOException`

### getTopChildren

public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException
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 class `Facets`
Throws:
  `IOException`

### getSpecificValue

public Number getSpecificValue(String dim, String... path) throws IOException
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 class `Facets`
Throws:
  `IOException`

### getAllDims

public List<FacetResult> getAllDims(int topN) throws IOException
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 class `Facets`
Throws:
  `IOException`