org.apache.solr.analytics.accumulator

## Class FacetingAccumulator

- java.lang.Object
- - org.apache.lucene.search.SimpleCollector
  - - org.apache.solr.analytics.accumulator.ValueAccumulator
    - - org.apache.solr.analytics.accumulator.BasicAccumulator
      - - org.apache.solr.analytics.accumulator.FacetingAccumulator

- All Implemented Interfaces:
    Collector, LeafCollector, FacetValueAccumulator

      public class FacetingAccumulator
      extends BasicAccumulator
      implements FacetValueAccumulator

  A `FacetingAccumulator` manages the StatsCollectors and Expressions for facets.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `FacetingAccumulator.EntryComparator` A comparator to compare expression values for field facet sorting.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected AnalyticsRequest` | `analyticsRequest`
    `protected boolean` | `basicsAndFieldFacetsComputed`
    `protected List<FieldFacetAccumulator>` | `facetAccumulators`
    `protected Map<String,Map<String,StatsCollector[]>>` | `fieldFacetCollectors`
    `protected Map<String,Map<String,Expression[]>>` | `fieldFacetExpressions`
    `protected Set<String>` | `hiddenFieldFacets`
    `protected LeafReaderContext` | `leaf`
    `protected int` | `leafNum`
    `static String` | `MISSING_VALUE`
    `protected long` | `queryCount`
    `protected Map<String,Map<String,StatsCollector[]>>` | `queryFacetCollectors`
    `protected Map<String,Map<String,Expression[]>>` | `queryFacetExpressions`
    `protected List<QueryFacetRequest>` | `queryFacets`
    `protected SolrQueryRequest` | `queryRequest` the current value of this stat field
    `protected Map<String,Map<String,StatsCollector[]>>` | `rangeFacetCollectors`
    `protected Map<String,Map<String,Expression[]>>` | `rangeFacetExpressions`
    `protected List<RangeFacetRequest>` | `rangeFacets`

    - ### Fields inherited from class org.apache.solr.analytics.accumulator.BasicAccumulator

      `context, docs, expressionNames, expressions, expressionStrings, hiddenExpressions, request, searcher, statsCollectorArraySupplier, statsCollectors`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FacetingAccumulator(SolrIndexSearcher searcher, DocSet docs, AnalyticsRequest request, SolrQueryRequest queryRequest)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `collect(int doc)` Called from Analytics stats, adds documents to the field facets and the super `BasicAccumulator`.
    `void` | `collectField(int doc, String facetField, String facetValue)` Given a document, fieldFacet field and facetValue, adds the document to the `StatsCollector`s held in the bucket corresponding to the fieldFacet field and facetValue.
    `void` | `collectQuery(int doc, String facetName, String query)` Given a document, queryFacet name and query, adds the document to the `StatsCollector`s held in the bucket corresponding to the queryFacet name and query.
    `void` | `collectRange(int doc, String facetField, String range)` Given a document, rangeFacet field and range, adds the document to the `StatsCollector`s held in the bucket corresponding to the rangeFacet field and range.
    `void` | `compute()` Finalizes the statistics within the each facet bucket before exporting;
    `void` | `computeQueryFacet(String facet)` Finalizes the statistics within the a specific query facet before exporting;
    `void` | `computeRangeFacet(String facet)` Finalizes the statistics within the a specific range facet before exporting;
    `static FacetingAccumulator` | `create(SolrIndexSearcher searcher, DocSet docs, AnalyticsRequest request, SolrQueryRequest queryRequest)`
    `protected void` | `doSetNextReader(LeafReaderContext context)` Update the readers for the `BasicAccumulator`, field facets and field facet `StatsCollector`s.
    `NamedList<?>` | `export()`
    `NamedList<?>` | `export(Expression[] expressionArr)` Exports a list of expressions as a NamedList
    `long` | `getNumQueries()` Used for JMX stats collecting.
    `String` | `getQueryResult(String currentFacet, String expressionName, String queryFacet, String facetValue)` Returns the value of an expression to use in a range or query facet.
    `String` | `getResult(String expressionName, String fieldFacet, String facetValue)` Returns the value of an expression to use in a range or query facet.
    `void` | `postProcess()` Processes the query and range facets.
    `void` | `processQueryFacets(Filter filter)` Initiates the collecting of query facets
    `void` | `processRangeFacets(Filter filter)` Initiates the collecting of range facets
    `void` | `setQueryStatsCollectorReaders(LeafReaderContext context)` Updates the reader for all of the query facet `StatsCollector`s.
    `void` | `setRangeStatsCollectorReaders(LeafReaderContext context)` Updates the reader for all of the range facet `StatsCollector`s.

    - ### Methods inherited from class org.apache.solr.analytics.accumulator.BasicAccumulator

      `create, getNumStatsCollectors, getResult, makeExpressions, needsScores`

    - ### Methods inherited from class org.apache.lucene.search.SimpleCollector

      `getLeafCollector, setScorer`

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

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

- - ### Field Detail

    - #### MISSING_VALUE

          public static final String MISSING_VALUE

      See Also:
        Constant Field Values

    - #### basicsAndFieldFacetsComputed

          protected boolean basicsAndFieldFacetsComputed

    - #### leafNum

          protected int leafNum

    - #### leaf

          protected LeafReaderContext leaf

    - #### analyticsRequest

          protected final AnalyticsRequest analyticsRequest

    - #### fieldFacetExpressions

          protected final Map<String,Map<String,Expression[]>> fieldFacetExpressions

    - #### rangeFacetExpressions

          protected final Map<String,Map<String,Expression[]>> rangeFacetExpressions

    - #### queryFacetExpressions

          protected final Map<String,Map<String,Expression[]>> queryFacetExpressions

    - #### fieldFacetCollectors

          protected final Map<String,Map<String,StatsCollector[]>> fieldFacetCollectors

    - #### rangeFacetCollectors

          protected final Map<String,Map<String,StatsCollector[]>> rangeFacetCollectors

    - #### queryFacetCollectors

          protected final Map<String,Map<String,StatsCollector[]>> queryFacetCollectors

    - #### facetAccumulators

          protected final List<FieldFacetAccumulator> facetAccumulators

    - #### hiddenFieldFacets

          protected final Set<String> hiddenFieldFacets

    - #### queryRequest

          protected final SolrQueryRequest queryRequest

      the current value of this stat field

    - #### rangeFacets

          protected List<RangeFacetRequest> rangeFacets

    - #### queryFacets

          protected List<QueryFacetRequest> queryFacets

    - #### queryCount

          protected long queryCount

  - ### Constructor Detail

    - #### FacetingAccumulator

          public FacetingAccumulator(SolrIndexSearcher searcher,
                                     DocSet docs,
                                     AnalyticsRequest request,
                                     SolrQueryRequest queryRequest)
                              throws IOException

      Throws:
        `IOException`

  - ### Method Detail

    - #### create

          public static FacetingAccumulator create(SolrIndexSearcher searcher,
                                                   DocSet docs,
                                                   AnalyticsRequest request,
                                                   SolrQueryRequest queryRequest)
                                            throws IOException

      Throws:
        `IOException`

    - #### doSetNextReader

          protected void doSetNextReader(LeafReaderContext context)
                                  throws IOException

      Update the readers for the `BasicAccumulator`, field facets and field facet `StatsCollector`s.
      Overrides:
        `doSetNextReader` in class `BasicAccumulator`
      Parameters:
        `context` - The context to read documents from.
      Throws:
        `IOException` - if there is an error setting the next reader

    - #### setRangeStatsCollectorReaders

          public void setRangeStatsCollectorReaders(LeafReaderContext context)
                                             throws IOException

      Updates the reader for all of the range facet `StatsCollector`s.
      Specified by:
        `setRangeStatsCollectorReaders` in interface `FacetValueAccumulator`
      Parameters:
        `context` - The context to read documents from.
      Throws:
        `IOException` - if there is an error setting the next reader

    - #### setQueryStatsCollectorReaders

          public void setQueryStatsCollectorReaders(LeafReaderContext context)
                                             throws IOException

      Updates the reader for all of the query facet `StatsCollector`s.
      Specified by:
        `setQueryStatsCollectorReaders` in interface `FacetValueAccumulator`
      Parameters:
        `context` - The context to read documents from.
      Throws:
        `IOException` - if there is an error setting the next reader

    - #### collect

          public void collect(int doc)
                       throws IOException

      Called from Analytics stats, adds documents to the field facets and the super `BasicAccumulator`.
      Specified by:
        `collect` in interface `LeafCollector`
      Overrides:
        `collect` in class `BasicAccumulator`
      Parameters:
        `doc` - Document to collect from
      Throws:
        `IOException`

    - #### collectField

          public void collectField(int doc,
                                   String facetField,
                                   String facetValue)
                            throws IOException

      Given a document, fieldFacet field and facetValue, adds the document to the `StatsCollector`s held in the bucket corresponding to the fieldFacet field and facetValue. Called during initial document collection.
      Specified by:
        `collectField` in interface `FacetValueAccumulator`
      Throws:
        `IOException`

    - #### collectRange

          public void collectRange(int doc,
                                   String facetField,
                                   String range)
                            throws IOException

      Given a document, rangeFacet field and range, adds the document to the `StatsCollector`s held in the bucket corresponding to the rangeFacet field and range. Called during post processing.
      Specified by:
        `collectRange` in interface `FacetValueAccumulator`
      Throws:
        `IOException`

    - #### collectQuery

          public void collectQuery(int doc,
                                   String facetName,
                                   String query)
                            throws IOException

      Given a document, queryFacet name and query, adds the document to the `StatsCollector`s held in the bucket corresponding to the queryFacet name and query. Called during post processing.
      Specified by:
        `collectQuery` in interface `FacetValueAccumulator`
      Throws:
        `IOException`

    - #### compute

          public void compute()

      Finalizes the statistics within the each facet bucket before exporting;
      Overrides:
        `compute` in class `BasicAccumulator`

    - #### computeQueryFacet

          public void computeQueryFacet(String facet)

      Finalizes the statistics within the a specific query facet before exporting;

    - #### computeRangeFacet

          public void computeRangeFacet(String facet)

      Finalizes the statistics within the a specific range facet before exporting;

    - #### getResult

          public String getResult(String expressionName,
                                  String fieldFacet,
                                  String facetValue)

      Returns the value of an expression to use in a range or query facet.
      Parameters:
        `expressionName` - the name of the expression
        `fieldFacet` - the facet field
        `facetValue` - the facet value
      Returns:
        String String representation of pivot value

    - #### getQueryResult

          public String getQueryResult(String currentFacet,
                                       String expressionName,
                                       String queryFacet,
                                       String facetValue)

      Returns the value of an expression to use in a range or query facet.
      Parameters:
        `currentFacet` - the name of the current facet
        `expressionName` - the name of the expression
        `queryFacet` - the facet query
        `facetValue` - the field value
      Returns:
        String String representation of pivot value

    - #### export

          public NamedList<?> export()

      Overrides:
        `export` in class `BasicAccumulator`

    - #### export

          public NamedList<?> export(Expression[] expressionArr)

      Exports a list of expressions as a NamedList
      Parameters:
        `expressionArr` - an array of expressions
      Returns:
        named list of expressions

    - #### postProcess

          public void postProcess()
                           throws IOException

      Processes the query and range facets. Must be called if range and/or query facets are supported.
      Overrides:
        `postProcess` in class `ValueAccumulator`
      Throws:
        `IOException`

    - #### processQueryFacets

          public void processQueryFacets(Filter filter)
                                  throws IOException

      Initiates the collecting of query facets
      Parameters:
        `filter` - the base filter to work against
      Throws:
        `IOException` - if searching failed

    - #### getNumQueries

          public long getNumQueries()

      Description copied from class: `BasicAccumulator`
      Used for JMX stats collecting. Counts the number of queries in all query facets
      Overrides:
        `getNumQueries` in class `BasicAccumulator`
      Returns:
        number of queries requested in all query facets.

    - #### processRangeFacets

          public void processRangeFacets(Filter filter)
                                  throws IOException

      Initiates the collecting of range facets
      Parameters:
        `filter` - the base filter to use
      Throws:
        `IOException` - if searching fails

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.