Package org.apache.lucene.spatial.prefix

## Class PrefixTreeFacetCounter

- java.lang.Object
- - org.apache.lucene.spatial.prefix.PrefixTreeFacetCounter

-     public class PrefixTreeFacetCounter
      extends Object

  Computes facets on cells for `PrefixTreeStrategy`.

  NOTE: If for a given document and a given field using `RecursivePrefixTreeStrategy` multiple values are indexed (i.e. multi-valued) and at least one of them is a non-point, then there is a possibility of double-counting the document in the facet results. Since each shape is independently turned into grid cells at a resolution chosen by the shape's size, it's possible they will be indexed at different resolutions. This means the document could be present in BOTH the postings for a cell in both its prefix and leaf variants. To avoid this, use a single valued field with a `ShapeCollection` (or WKT equivalent). Or calculate a suitable level/distErr to index both and call `PrefixTreeStrategy.createIndexableFields(org.locationtech.spatial4j.shape.Shape, int)` with the same value for all shapes for a given document/field.

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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `PrefixTreeFacetCounter.FacetVisitor` | A callback/visitor of facet counts.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static void` | `compute​(PrefixTreeStrategy strategy, IndexReaderContext context, Bits topAcceptDocs, org.locationtech.spatial4j.shape.Shape queryShape, int facetLevel, PrefixTreeFacetCounter.FacetVisitor facetVisitor)` | Computes facets using a callback/visitor style design, allowing flexibility for the caller to determine what to do with each underlying count.
    `static void` | `compute​(PrefixTreeStrategy strategy, LeafReaderContext context, Bits acceptDocs, org.locationtech.spatial4j.shape.Shape queryShape, int facetLevel, PrefixTreeFacetCounter.FacetVisitor facetVisitor)` | Lower-level per-leaf segment method.

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

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

- - ### Method Detail

    - #### compute

          public static void compute​(PrefixTreeStrategy strategy,
                                     IndexReaderContext context,
                                     Bits topAcceptDocs,
                                     org.locationtech.spatial4j.shape.Shape queryShape,
                                     int facetLevel,
                                     PrefixTreeFacetCounter.FacetVisitor facetVisitor)
                              throws IOException

      Computes facets using a callback/visitor style design, allowing flexibility for the caller to determine what to do with each underlying count.
      Parameters:
        `strategy` - the prefix tree strategy (contains the field reference, grid, max levels)
        `context` - the IndexReader's context
        `topAcceptDocs` - a Bits to limit counted docs. If null, live docs are counted.
        `queryShape` - the shape to limit the range of facet counts to
        `facetLevel` - the maximum depth (detail) of faceted cells
        `facetVisitor` - the visitor/callback to receive the counts
      Throws:
        `IOException`

    - #### compute

          public static void compute​(PrefixTreeStrategy strategy,
                                     LeafReaderContext context,
                                     Bits acceptDocs,
                                     org.locationtech.spatial4j.shape.Shape queryShape,
                                     int facetLevel,
                                     PrefixTreeFacetCounter.FacetVisitor facetVisitor)
                              throws IOException

      Lower-level per-leaf segment method.
      Throws:
        `IOException`