org.apache.lucene.search

## Class FieldCacheRangeFilter

- java.lang.Object
- - org.apache.lucene.search.Filter
  - - org.apache.lucene.search.FieldCacheRangeFilter

- All Implemented Interfaces:
    java.io.Serializable

      public abstract class FieldCacheRangeFilter
      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` (or `ConstantScoreRangeQuery` on a `TermRangeFilter`) for each query, 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 `NumericField`. 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`.

  See Also:
    Serialized Form

- - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(java.lang.Object o)`
    `abstract DocIdSet` | `getDocIdSet(IndexReader reader)` This method is implemented for each data type
    `int` | `hashCode()`
    `static FieldCacheRangeFilter` | `newByteRange(java.lang.String field, java.lang.Byte lowerVal, java.lang.Byte upperVal, boolean includeLower, boolean includeUpper)` Creates a numeric range query using `FieldCache.getBytes(IndexReader,String)`.
    `static FieldCacheRangeFilter` | `newByteRange(java.lang.String field, FieldCache.ByteParser parser, java.lang.Byte lowerVal, java.lang.Byte upperVal, boolean includeLower, boolean includeUpper)` Creates a numeric range query using `FieldCache.getBytes(IndexReader,String,FieldCache.ByteParser)`.
    `static FieldCacheRangeFilter` | `newDoubleRange(java.lang.String field, java.lang.Double lowerVal, java.lang.Double upperVal, boolean includeLower, boolean includeUpper)` Creates a numeric range query using `FieldCache.getDoubles(IndexReader,String)`.
    `static FieldCacheRangeFilter` | `newDoubleRange(java.lang.String field, FieldCache.DoubleParser parser, java.lang.Double lowerVal, java.lang.Double upperVal, boolean includeLower, boolean includeUpper)` Creates a numeric range query using `FieldCache.getDoubles(IndexReader,String,FieldCache.DoubleParser)`.
    `static FieldCacheRangeFilter` | `newFloatRange(java.lang.String field, FieldCache.FloatParser parser, java.lang.Float lowerVal, java.lang.Float upperVal, boolean includeLower, boolean includeUpper)` Creates a numeric range query using `FieldCache.getFloats(IndexReader,String,FieldCache.FloatParser)`.
    `static FieldCacheRangeFilter` | `newFloatRange(java.lang.String field, java.lang.Float lowerVal, java.lang.Float upperVal, boolean includeLower, boolean includeUpper)` Creates a numeric range query using `FieldCache.getFloats(IndexReader,String)`.
    `static FieldCacheRangeFilter` | `newIntRange(java.lang.String field, FieldCache.IntParser parser, java.lang.Integer lowerVal, java.lang.Integer upperVal, boolean includeLower, boolean includeUpper)` Creates a numeric range query using `FieldCache.getInts(IndexReader,String,FieldCache.IntParser)`.
    `static FieldCacheRangeFilter` | `newIntRange(java.lang.String field, java.lang.Integer lowerVal, java.lang.Integer upperVal, boolean includeLower, boolean includeUpper)` Creates a numeric range query using `FieldCache.getInts(IndexReader,String)`.
    `static FieldCacheRangeFilter` | `newLongRange(java.lang.String field, FieldCache.LongParser parser, java.lang.Long lowerVal, java.lang.Long upperVal, boolean includeLower, boolean includeUpper)` Creates a numeric range query using `FieldCache.getLongs(IndexReader,String,FieldCache.LongParser)`.
    `static FieldCacheRangeFilter` | `newLongRange(java.lang.String field, java.lang.Long lowerVal, java.lang.Long upperVal, boolean includeLower, boolean includeUpper)` Creates a numeric range query using `FieldCache.getLongs(IndexReader,String)`.
    `static FieldCacheRangeFilter` | `newShortRange(java.lang.String field, FieldCache.ShortParser parser, java.lang.Short lowerVal, java.lang.Short upperVal, boolean includeLower, boolean includeUpper)` Creates a numeric range query using `FieldCache.getShorts(IndexReader,String,FieldCache.ShortParser)`.
    `static FieldCacheRangeFilter` | `newShortRange(java.lang.String field, java.lang.Short lowerVal, java.lang.Short upperVal, boolean includeLower, boolean includeUpper)` Creates a numeric range query using `FieldCache.getShorts(IndexReader,String)`.
    `static FieldCacheRangeFilter` | `newStringRange(java.lang.String field, java.lang.String lowerVal, java.lang.String upperVal, boolean includeLower, boolean includeUpper)` Creates a string range query using `FieldCache.getStringIndex(org.apache.lucene.index.IndexReader, java.lang.String)`.
    `java.lang.String` | `toString()`

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

      `bits`

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

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Method Detail

    - #### getDocIdSet

          public abstract DocIdSet getDocIdSet(IndexReader reader)
                                        throws java.io.IOException

      This method is implemented for each data type
      Overrides:
        `getDocIdSet` in class `Filter`
      Parameters:
        `reader` - a `IndexReader` instance opened on the index currently searched on. Note, it is likely that the provided reader does not represent the whole underlying index i.e. if the index has more than one segment the given reader only represents a single segment.
      Returns:
        a DocIdSet that provides the documents which should be permitted or prohibited in search results. NOTE: null can be returned if no documents will be accepted by this Filter.
      Throws:
        `java.io.IOException`
      See Also:
        `DocIdBitSet`

    - #### newStringRange

          public static FieldCacheRangeFilter newStringRange(java.lang.String field,
                                                             java.lang.String lowerVal,
                                                             java.lang.String upperVal,
                                                             boolean includeLower,
                                                             boolean includeUpper)

      Creates a string range query using `FieldCache.getStringIndex(org.apache.lucene.index.IndexReader, java.lang.String)`. This works with all fields containing zero or one term in the field. The range can be half-open by setting one of the values to `null`.

    - #### newByteRange

          public static FieldCacheRangeFilter newByteRange(java.lang.String field,
                                                           java.lang.Byte lowerVal,
                                                           java.lang.Byte upperVal,
                                                           boolean includeLower,
                                                           boolean includeUpper)

      Creates a numeric range query using `FieldCache.getBytes(IndexReader,String)`. This works with all byte fields containing exactly one numeric term in the field. The range can be half-open by setting one of the values to `null`.

    - #### newByteRange

          public static FieldCacheRangeFilter newByteRange(java.lang.String field,
                                                           FieldCache.ByteParser parser,
                                                           java.lang.Byte lowerVal,
                                                           java.lang.Byte upperVal,
                                                           boolean includeLower,
                                                           boolean includeUpper)

      Creates a numeric range query using `FieldCache.getBytes(IndexReader,String,FieldCache.ByteParser)`. This works with all byte fields containing exactly one numeric term in the field. The range can be half-open by setting one of the values to `null`.

    - #### newShortRange

          public static FieldCacheRangeFilter newShortRange(java.lang.String field,
                                                            java.lang.Short lowerVal,
                                                            java.lang.Short upperVal,
                                                            boolean includeLower,
                                                            boolean includeUpper)

      Creates a numeric range query using `FieldCache.getShorts(IndexReader,String)`. This works with all short fields containing exactly one numeric term in the field. The range can be half-open by setting one of the values to `null`.

    - #### newShortRange

          public static FieldCacheRangeFilter newShortRange(java.lang.String field,
                                                            FieldCache.ShortParser parser,
                                                            java.lang.Short lowerVal,
                                                            java.lang.Short upperVal,
                                                            boolean includeLower,
                                                            boolean includeUpper)

      Creates a numeric range query using `FieldCache.getShorts(IndexReader,String,FieldCache.ShortParser)`. This works with all short fields containing exactly one numeric term in the field. The range can be half-open by setting one of the values to `null`.

    - #### newIntRange

          public static FieldCacheRangeFilter newIntRange(java.lang.String field,
                                                          java.lang.Integer lowerVal,
                                                          java.lang.Integer upperVal,
                                                          boolean includeLower,
                                                          boolean includeUpper)

      Creates a numeric range query using `FieldCache.getInts(IndexReader,String)`. This works with all int fields containing exactly one numeric term in the field. The range can be half-open by setting one of the values to `null`.

    - #### newIntRange

          public static FieldCacheRangeFilter newIntRange(java.lang.String field,
                                                          FieldCache.IntParser parser,
                                                          java.lang.Integer lowerVal,
                                                          java.lang.Integer upperVal,
                                                          boolean includeLower,
                                                          boolean includeUpper)

      Creates a numeric range query using `FieldCache.getInts(IndexReader,String,FieldCache.IntParser)`. This works with all int fields containing exactly one numeric term in the field. The range can be half-open by setting one of the values to `null`.

    - #### newLongRange

          public static FieldCacheRangeFilter newLongRange(java.lang.String field,
                                                           java.lang.Long lowerVal,
                                                           java.lang.Long upperVal,
                                                           boolean includeLower,
                                                           boolean includeUpper)

      Creates a numeric range query using `FieldCache.getLongs(IndexReader,String)`. This works with all long fields containing exactly one numeric term in the field. The range can be half-open by setting one of the values to `null`.

    - #### newLongRange

          public static FieldCacheRangeFilter newLongRange(java.lang.String field,
                                                           FieldCache.LongParser parser,
                                                           java.lang.Long lowerVal,
                                                           java.lang.Long upperVal,
                                                           boolean includeLower,
                                                           boolean includeUpper)

      Creates a numeric range query using `FieldCache.getLongs(IndexReader,String,FieldCache.LongParser)`. This works with all long fields containing exactly one numeric term in the field. The range can be half-open by setting one of the values to `null`.

    - #### newFloatRange

          public static FieldCacheRangeFilter newFloatRange(java.lang.String field,
                                                            java.lang.Float lowerVal,
                                                            java.lang.Float upperVal,
                                                            boolean includeLower,
                                                            boolean includeUpper)

      Creates a numeric range query using `FieldCache.getFloats(IndexReader,String)`. This works with all float fields containing exactly one numeric term in the field. The range can be half-open by setting one of the values to `null`.

    - #### newFloatRange

          public static FieldCacheRangeFilter newFloatRange(java.lang.String field,
                                                            FieldCache.FloatParser parser,
                                                            java.lang.Float lowerVal,
                                                            java.lang.Float upperVal,
                                                            boolean includeLower,
                                                            boolean includeUpper)

      Creates a numeric range query using `FieldCache.getFloats(IndexReader,String,FieldCache.FloatParser)`. This works with all float fields containing exactly one numeric term in the field. The range can be half-open by setting one of the values to `null`.

    - #### newDoubleRange

          public static FieldCacheRangeFilter newDoubleRange(java.lang.String field,
                                                             java.lang.Double lowerVal,
                                                             java.lang.Double upperVal,
                                                             boolean includeLower,
                                                             boolean includeUpper)

      Creates a numeric range query using `FieldCache.getDoubles(IndexReader,String)`. This works with all double fields containing exactly one numeric term in the field. The range can be half-open by setting one of the values to `null`.

    - #### newDoubleRange

          public static FieldCacheRangeFilter newDoubleRange(java.lang.String field,
                                                             FieldCache.DoubleParser parser,
                                                             java.lang.Double lowerVal,
                                                             java.lang.Double upperVal,
                                                             boolean includeLower,
                                                             boolean includeUpper)

      Creates a numeric range query using `FieldCache.getDoubles(IndexReader,String,FieldCache.DoubleParser)`. This works with all double fields containing exactly one numeric term in the field. The range can be half-open by setting one of the values to `null`.

    - #### toString

          public final java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### equals

          public final boolean equals(java.lang.Object o)

      Overrides:
        `equals` in class `java.lang.Object`

    - #### hashCode

          public final int hashCode()

      Overrides:
        `hashCode` in class `java.lang.Object`

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