Class LongRangeCounter

java.lang.Object
org.apache.lucene.facet.range.LongRangeCounter
Direct Known Subclasses:
ExclusiveLongRangeCounter, OverlappingLongRangeCounter

abstract class LongRangeCounter extends Object
Counter for numeric ranges. Works for both single- and multi-valued cases (assuming you use it correctly).

Usage notes: When counting a document field that only has a single value, callers should call addSingleValued() with the value. Whenever a document field has multiple values, callers should call startMultiValuedDoc() at the beginning of processing the document, followed by addMultiValued() with each value before finally calling endMultiValuedDoc() at the end of processing the document. The call to endMultiValuedDoc() will respond with a boolean indicating whether-or-not the specific document matched against at least one of the ranges being counted. Finally, after processing all documents, the caller should call finish(). This final call will ensure the contents of the user-provided countBuffer contains accurate counts (each index corresponding to the provided LongRange in ranges). The final call to finish() will also report how many additional documents did not match against any ranges. The combination of the endMultiValuedDoc() boolean responses and the number reported by finish() communicates the total number of missing documents. Note that the call to finish() will not report any documents already reported missing by endMultiValuedDoc().

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static final class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final int[]
    accumulated counts for all of the ranges
    protected int
    for multi-value docs, we keep track of the last elementary interval we've counted so we can use that as a lower-bound when counting subsequent values.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    LongRangeCounter(int[] countBuffer)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) void
    Count a multi-valued doc value
    (package private) void
    Count a single valued doc
    protected abstract long[]
    Provide boundary information for elementary intervals (max inclusive value per interval)
    (package private) static LongRangeCounter
    create(LongRange[] ranges, int[] countBuffer)
     
    (package private) abstract boolean
    Finish processing a new doc.
    (package private) abstract int
    Finish processing all documents.
    private static boolean
    Determine whether-or-not any requested ranges overlap
    protected final void
    increment(int rangeNum)
    Increment the specified range by one.
    protected final void
    increment(int rangeNum, int count)
    Increment the specified range by the specified count.
    protected abstract void
    processMultiValuedHit(int elementaryIntervalNum)
    Process a multi-value "hit" against an elementary interval.
    protected abstract void
    processSingleValuedHit(int elementaryIntervalNum)
    Process a single-value "hit" against an elementary interval.
    protected final int
    Number of ranges requested by the caller.
    (package private) void
    Start processing a new doc.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • countBuffer

      private final int[] countBuffer
      accumulated counts for all of the ranges
    • multiValuedDocLastSeenElementaryInterval

      protected int multiValuedDocLastSeenElementaryInterval
      for multi-value docs, we keep track of the last elementary interval we've counted so we can use that as a lower-bound when counting subsequent values. this takes advantage of the fact that values within a given doc are sorted.
  • Constructor Details

    • LongRangeCounter

      protected LongRangeCounter(int[] countBuffer)
  • Method Details

    • create

      static LongRangeCounter create(LongRange[] ranges, int[] countBuffer)
    • startMultiValuedDoc

      void startMultiValuedDoc()
      Start processing a new doc. It's unnecessary to call this for single-value cases.
    • endMultiValuedDoc

      abstract boolean endMultiValuedDoc()
      Finish processing a new doc. Returns whether-or-not the document contributed a count to at least one range. It's unnecessary to call this for single-value cases.
    • addSingleValued

      void addSingleValued(long v)
      Count a single valued doc
    • addMultiValued

      void addMultiValued(long v)
      Count a multi-valued doc value
    • finish

      abstract int finish()
      Finish processing all documents. This will return the number of docs that didn't contribute to any ranges (that weren't already reported when calling endMultiValuedDoc()).
    • boundaries

      protected abstract long[] boundaries()
      Provide boundary information for elementary intervals (max inclusive value per interval)
    • processSingleValuedHit

      protected abstract void processSingleValuedHit(int elementaryIntervalNum)
      Process a single-value "hit" against an elementary interval.
    • processMultiValuedHit

      protected abstract void processMultiValuedHit(int elementaryIntervalNum)
      Process a multi-value "hit" against an elementary interval.
    • increment

      protected final void increment(int rangeNum)
      Increment the specified range by one.
    • increment

      protected final void increment(int rangeNum, int count)
      Increment the specified range by the specified count.
    • rangeCount

      protected final int rangeCount()
      Number of ranges requested by the caller.
    • hasOverlappingRanges

      private static boolean hasOverlappingRanges(LongRange[] ranges)
      Determine whether-or-not any requested ranges overlap