Class FieldCacheRangeFilter<T>


  • public abstract class FieldCacheRangeFilter<T>
    extends Filter
    A range filter built on top of a cached single term field (in FieldCache).

    FieldCacheRangeFilter builds a single cache for the field the first time it is used. Each subsequent FieldCacheRangeFilter on the same field then reuses this cache, even if the range itself changes.

    This means that FieldCacheRangeFilter is much faster (sometimes more than 100x as fast) as building a TermRangeFilter, if using a newStringRange(java.lang.String, java.lang.String, java.lang.String, boolean, boolean). However, if the range never changes it is slower (around 2x as slow) than building a CachingWrapperFilter on top of a single TermRangeFilter. For numeric data types, this filter may be significantly faster than NumericRangeFilter. Furthermore, it does not need the numeric values encoded by IntField, FloatField, LongField or DoubleField. But it has the problem that it only works with exact one value/document (see below).

    As with all FieldCache based functionality, FieldCacheRangeFilter is only valid for fields which exact one term for each document (except for newStringRange(java.lang.String, java.lang.String, java.lang.String, boolean, boolean) where 0 terms are also allowed). Due to a restriction of FieldCache, for numeric ranges all terms that do not have a numeric value, 0 is assumed.

    Thus it works on dates, prices and other single value fields but will not work on regular text fields. It is preferable to use a NOT_ANALYZED field to ensure that there is only a single term.

    This class does not have an constructor, use one of the static factory methods available, that create a correct instance for different data types supported by FieldCache.