org.apache.lucene.search
Class FieldCacheRangeFilter<T>

java.lang.Object
  extended by org.apache.lucene.search.Filter
      extended by org.apache.lucene.search.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.


Method Summary
 boolean equals(Object o)
           
abstract  DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs)
          This method is implemented for each data type
 String getField()
          Returns the field name for this filter
 T getLowerVal()
          Returns the lower value of this range filter
 FieldCache.Parser getParser()
          Returns the current numeric parser (null for T is String}
 T getUpperVal()
          Returns the upper value of this range filter
 int hashCode()
           
 boolean includesLower()
          Returns true if the lower endpoint is inclusive
 boolean includesUpper()
          Returns true if the upper endpoint is inclusive
static FieldCacheRangeFilter<Byte> newByteRange(String field, Byte lowerVal, Byte upperVal, boolean includeLower, boolean includeUpper)
          Deprecated. 
static FieldCacheRangeFilter<Byte> newByteRange(String field, FieldCache.ByteParser parser, Byte lowerVal, Byte upperVal, boolean includeLower, boolean includeUpper)
          Deprecated. 
static FieldCacheRangeFilter<BytesRef> newBytesRefRange(String field, BytesRef lowerVal, BytesRef upperVal, boolean includeLower, boolean includeUpper)
          Creates a BytesRef range filter using FieldCache.getTermsIndex(org.apache.lucene.index.AtomicReader, java.lang.String).
static FieldCacheRangeFilter<Double> newDoubleRange(String field, Double lowerVal, Double upperVal, boolean includeLower, boolean includeUpper)
          Creates a numeric range filter using FieldCache.getDoubles(AtomicReader,String,boolean).
static FieldCacheRangeFilter<Double> newDoubleRange(String field, FieldCache.DoubleParser parser, Double lowerVal, Double upperVal, boolean includeLower, boolean includeUpper)
          Creates a numeric range filter using FieldCache.getDoubles(AtomicReader,String,FieldCache.DoubleParser,boolean).
static FieldCacheRangeFilter<Float> newFloatRange(String field, FieldCache.FloatParser parser, Float lowerVal, Float upperVal, boolean includeLower, boolean includeUpper)
          Creates a numeric range filter using FieldCache.getFloats(AtomicReader,String,FieldCache.FloatParser,boolean).
static FieldCacheRangeFilter<Float> newFloatRange(String field, Float lowerVal, Float upperVal, boolean includeLower, boolean includeUpper)
          Creates a numeric range filter using FieldCache.getFloats(AtomicReader,String,boolean).
static FieldCacheRangeFilter<Integer> newIntRange(String field, FieldCache.IntParser parser, Integer lowerVal, Integer upperVal, boolean includeLower, boolean includeUpper)
          Creates a numeric range filter using FieldCache.getInts(AtomicReader,String,FieldCache.IntParser,boolean).
static FieldCacheRangeFilter<Integer> newIntRange(String field, Integer lowerVal, Integer upperVal, boolean includeLower, boolean includeUpper)
          Creates a numeric range filter using FieldCache.getInts(AtomicReader,String,boolean).
static FieldCacheRangeFilter<Long> newLongRange(String field, FieldCache.LongParser parser, Long lowerVal, Long upperVal, boolean includeLower, boolean includeUpper)
          Creates a numeric range filter using FieldCache.getLongs(AtomicReader,String,FieldCache.LongParser,boolean).
static FieldCacheRangeFilter<Long> newLongRange(String field, Long lowerVal, Long upperVal, boolean includeLower, boolean includeUpper)
          Creates a numeric range filter using FieldCache.getLongs(AtomicReader,String,boolean).
static FieldCacheRangeFilter<Short> newShortRange(String field, FieldCache.ShortParser parser, Short lowerVal, Short upperVal, boolean includeLower, boolean includeUpper)
          Deprecated. 
static FieldCacheRangeFilter<Short> newShortRange(String field, Short lowerVal, Short upperVal, boolean includeLower, boolean includeUpper)
          Deprecated. 
static FieldCacheRangeFilter<String> newStringRange(String field, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper)
          Creates a string range filter using FieldCache.getTermsIndex(org.apache.lucene.index.AtomicReader, java.lang.String).
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getDocIdSet

public abstract DocIdSet getDocIdSet(AtomicReaderContext context,
                                     Bits acceptDocs)
                              throws IOException
This method is implemented for each data type

Specified by:
getDocIdSet in class Filter
Parameters:
context - a AtomicReaderContext instance opened on the index currently searched on. Note, it is likely that the provided reader info 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. The provided context is always an atomic context, so you can call AtomicReader.fields() on the context's reader, for example.
acceptDocs - Bits that represent the allowable docs to match (typically deleted docs but possibly filtering other documents)
Returns:
a DocIdSet that provides the documents which should be permitted or prohibited in search results. NOTE: null should be returned if the filter doesn't accept any documents otherwise internal optimization might not apply in the case an empty DocIdSet is returned.
Throws:
IOException

newStringRange

public static FieldCacheRangeFilter<String> newStringRange(String field,
                                                           String lowerVal,
                                                           String upperVal,
                                                           boolean includeLower,
                                                           boolean includeUpper)
Creates a string range filter using FieldCache.getTermsIndex(org.apache.lucene.index.AtomicReader, 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.


newBytesRefRange

public static FieldCacheRangeFilter<BytesRef> newBytesRefRange(String field,
                                                               BytesRef lowerVal,
                                                               BytesRef upperVal,
                                                               boolean includeLower,
                                                               boolean includeUpper)
Creates a BytesRef range filter using FieldCache.getTermsIndex(org.apache.lucene.index.AtomicReader, 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

@Deprecated
public static FieldCacheRangeFilter<Byte> newByteRange(String field,
                                                                  Byte lowerVal,
                                                                  Byte upperVal,
                                                                  boolean includeLower,
                                                                  boolean includeUpper)
Deprecated. 

Creates a numeric range filter using FieldCache.getBytes(AtomicReader,String,boolean). 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

@Deprecated
public static FieldCacheRangeFilter<Byte> newByteRange(String field,
                                                                  FieldCache.ByteParser parser,
                                                                  Byte lowerVal,
                                                                  Byte upperVal,
                                                                  boolean includeLower,
                                                                  boolean includeUpper)
Deprecated. 

Creates a numeric range filter using FieldCache.getBytes(AtomicReader,String,FieldCache.ByteParser,boolean). 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

@Deprecated
public static FieldCacheRangeFilter<Short> newShortRange(String field,
                                                                    Short lowerVal,
                                                                    Short upperVal,
                                                                    boolean includeLower,
                                                                    boolean includeUpper)
Deprecated. 

Creates a numeric range filter using FieldCache.getShorts(AtomicReader,String,boolean). 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

@Deprecated
public static FieldCacheRangeFilter<Short> newShortRange(String field,
                                                                    FieldCache.ShortParser parser,
                                                                    Short lowerVal,
                                                                    Short upperVal,
                                                                    boolean includeLower,
                                                                    boolean includeUpper)
Deprecated. 

Creates a numeric range filter using FieldCache.getShorts(AtomicReader,String,FieldCache.ShortParser,boolean). 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<Integer> newIntRange(String field,
                                                         Integer lowerVal,
                                                         Integer upperVal,
                                                         boolean includeLower,
                                                         boolean includeUpper)
Creates a numeric range filter using FieldCache.getInts(AtomicReader,String,boolean). 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<Integer> newIntRange(String field,
                                                         FieldCache.IntParser parser,
                                                         Integer lowerVal,
                                                         Integer upperVal,
                                                         boolean includeLower,
                                                         boolean includeUpper)
Creates a numeric range filter using FieldCache.getInts(AtomicReader,String,FieldCache.IntParser,boolean). 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<Long> newLongRange(String field,
                                                       Long lowerVal,
                                                       Long upperVal,
                                                       boolean includeLower,
                                                       boolean includeUpper)
Creates a numeric range filter using FieldCache.getLongs(AtomicReader,String,boolean). 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<Long> newLongRange(String field,
                                                       FieldCache.LongParser parser,
                                                       Long lowerVal,
                                                       Long upperVal,
                                                       boolean includeLower,
                                                       boolean includeUpper)
Creates a numeric range filter using FieldCache.getLongs(AtomicReader,String,FieldCache.LongParser,boolean). 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<Float> newFloatRange(String field,
                                                         Float lowerVal,
                                                         Float upperVal,
                                                         boolean includeLower,
                                                         boolean includeUpper)
Creates a numeric range filter using FieldCache.getFloats(AtomicReader,String,boolean). 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<Float> newFloatRange(String field,
                                                         FieldCache.FloatParser parser,
                                                         Float lowerVal,
                                                         Float upperVal,
                                                         boolean includeLower,
                                                         boolean includeUpper)
Creates a numeric range filter using FieldCache.getFloats(AtomicReader,String,FieldCache.FloatParser,boolean). 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<Double> newDoubleRange(String field,
                                                           Double lowerVal,
                                                           Double upperVal,
                                                           boolean includeLower,
                                                           boolean includeUpper)
Creates a numeric range filter using FieldCache.getDoubles(AtomicReader,String,boolean). 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<Double> newDoubleRange(String field,
                                                           FieldCache.DoubleParser parser,
                                                           Double lowerVal,
                                                           Double upperVal,
                                                           boolean includeLower,
                                                           boolean includeUpper)
Creates a numeric range filter using FieldCache.getDoubles(AtomicReader,String,FieldCache.DoubleParser,boolean). 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 String toString()
Overrides:
toString in class Object

equals

public final boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public final int hashCode()
Overrides:
hashCode in class Object

getField

public String getField()
Returns the field name for this filter


includesLower

public boolean includesLower()
Returns true if the lower endpoint is inclusive


includesUpper

public boolean includesUpper()
Returns true if the upper endpoint is inclusive


getLowerVal

public T getLowerVal()
Returns the lower value of this range filter


getUpperVal

public T getUpperVal()
Returns the upper value of this range filter


getParser

public FieldCache.Parser getParser()
Returns the current numeric parser (null for T is String}



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