Class FieldCacheRangeFilter<T>
- java.lang.Object
-
- org.apache.lucene.search.Filter
-
- 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 (inFieldCache).FieldCacheRangeFilterbuilds a single cache for the field the first time it is used. Each subsequentFieldCacheRangeFilteron the same field then reuses this cache, even if the range itself changes.This means that
FieldCacheRangeFilteris much faster (sometimes more than 100x as fast) as building aTermRangeFilter, if using anewStringRange(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 singleTermRangeFilter. For numeric data types, this filter may be significantly faster thanNumericRangeFilter. Furthermore, it does not need the numeric values encoded byIntField,FloatField,LongFieldorDoubleField. But it has the problem that it only works with exact one value/document (see below).As with all
FieldCachebased functionality,FieldCacheRangeFilteris only valid for fields which exact one term for each document (except fornewStringRange(java.lang.String, java.lang.String, java.lang.String, boolean, boolean)where 0 terms are also allowed). Due to a restriction ofFieldCache, 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_ANALYZEDfield 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
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanequals(java.lang.Object o)abstract DocIdSetgetDocIdSet(AtomicReaderContext context, Bits acceptDocs)This method is implemented for each data typejava.lang.StringgetField()Returns the field name for this filterTgetLowerVal()Returns the lower value of this range filterFieldCache.ParsergetParser()Returns the current numeric parser (nullforTisString}TgetUpperVal()Returns the upper value of this range filterinthashCode()booleanincludesLower()Returnstrueif the lower endpoint is inclusivebooleanincludesUpper()Returnstrueif the upper endpoint is inclusivestatic FieldCacheRangeFilter<java.lang.Byte>newByteRange(java.lang.String field, java.lang.Byte lowerVal, java.lang.Byte upperVal, boolean includeLower, boolean includeUpper)Deprecated.static FieldCacheRangeFilter<java.lang.Byte>newByteRange(java.lang.String field, FieldCache.ByteParser parser, java.lang.Byte lowerVal, java.lang.Byte upperVal, boolean includeLower, boolean includeUpper)Deprecated.static FieldCacheRangeFilter<BytesRef>newBytesRefRange(java.lang.String field, BytesRef lowerVal, BytesRef upperVal, boolean includeLower, boolean includeUpper)Creates a BytesRef range filter usingFieldCache.getTermsIndex(org.apache.lucene.index.AtomicReader, java.lang.String).static FieldCacheRangeFilter<java.lang.Double>newDoubleRange(java.lang.String field, java.lang.Double lowerVal, java.lang.Double upperVal, boolean includeLower, boolean includeUpper)Creates a numeric range filter usingFieldCache.getDoubles(AtomicReader,String,boolean).static FieldCacheRangeFilter<java.lang.Double>newDoubleRange(java.lang.String field, FieldCache.DoubleParser parser, java.lang.Double lowerVal, java.lang.Double upperVal, boolean includeLower, boolean includeUpper)Creates a numeric range filter usingFieldCache.getDoubles(AtomicReader,String,FieldCache.DoubleParser,boolean).static FieldCacheRangeFilter<java.lang.Float>newFloatRange(java.lang.String field, java.lang.Float lowerVal, java.lang.Float upperVal, boolean includeLower, boolean includeUpper)Creates a numeric range filter usingFieldCache.getFloats(AtomicReader,String,boolean).static FieldCacheRangeFilter<java.lang.Float>newFloatRange(java.lang.String field, FieldCache.FloatParser parser, java.lang.Float lowerVal, java.lang.Float upperVal, boolean includeLower, boolean includeUpper)Creates a numeric range filter usingFieldCache.getFloats(AtomicReader,String,FieldCache.FloatParser,boolean).static FieldCacheRangeFilter<java.lang.Integer>newIntRange(java.lang.String field, java.lang.Integer lowerVal, java.lang.Integer upperVal, boolean includeLower, boolean includeUpper)Creates a numeric range filter usingFieldCache.getInts(AtomicReader,String,boolean).static FieldCacheRangeFilter<java.lang.Integer>newIntRange(java.lang.String field, FieldCache.IntParser parser, java.lang.Integer lowerVal, java.lang.Integer upperVal, boolean includeLower, boolean includeUpper)Creates a numeric range filter usingFieldCache.getInts(AtomicReader,String,FieldCache.IntParser,boolean).static FieldCacheRangeFilter<java.lang.Long>newLongRange(java.lang.String field, java.lang.Long lowerVal, java.lang.Long upperVal, boolean includeLower, boolean includeUpper)Creates a numeric range filter usingFieldCache.getLongs(AtomicReader,String,boolean).static FieldCacheRangeFilter<java.lang.Long>newLongRange(java.lang.String field, FieldCache.LongParser parser, java.lang.Long lowerVal, java.lang.Long upperVal, boolean includeLower, boolean includeUpper)Creates a numeric range filter usingFieldCache.getLongs(AtomicReader,String,FieldCache.LongParser,boolean).static FieldCacheRangeFilter<java.lang.Short>newShortRange(java.lang.String field, java.lang.Short lowerVal, java.lang.Short upperVal, boolean includeLower, boolean includeUpper)Deprecated.static FieldCacheRangeFilter<java.lang.Short>newShortRange(java.lang.String field, FieldCache.ShortParser parser, java.lang.Short lowerVal, java.lang.Short upperVal, boolean includeLower, boolean includeUpper)Deprecated.static FieldCacheRangeFilter<java.lang.String>newStringRange(java.lang.String field, java.lang.String lowerVal, java.lang.String upperVal, boolean includeLower, boolean includeUpper)Creates a string range filter usingFieldCache.getTermsIndex(org.apache.lucene.index.AtomicReader, java.lang.String).java.lang.StringtoString()
-
-
-
Method Detail
-
getDocIdSet
public abstract DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws java.io.IOException
This method is implemented for each data type- Specified by:
getDocIdSetin classFilter- Parameters:
context- aAtomicReaderContextinstance 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 callAtomicReader.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:
nullshould be returned if the filter doesn't accept any documents otherwise internal optimization might not apply in the case an emptyDocIdSetis returned. - Throws:
java.io.IOException
-
newStringRange
public static FieldCacheRangeFilter<java.lang.String> newStringRange(java.lang.String field, java.lang.String lowerVal, java.lang.String upperVal, boolean includeLower, boolean includeUpper)
Creates a string range filter usingFieldCache.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 tonull.
-
newBytesRefRange
public static FieldCacheRangeFilter<BytesRef> newBytesRefRange(java.lang.String field, BytesRef lowerVal, BytesRef upperVal, boolean includeLower, boolean includeUpper)
Creates a BytesRef range filter usingFieldCache.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 tonull.
-
newByteRange
@Deprecated public static FieldCacheRangeFilter<java.lang.Byte> newByteRange(java.lang.String field, java.lang.Byte lowerVal, java.lang.Byte upperVal, boolean includeLower, boolean includeUpper)
Deprecated.Creates a numeric range filter usingFieldCache.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 tonull.
-
newByteRange
@Deprecated public static FieldCacheRangeFilter<java.lang.Byte> newByteRange(java.lang.String field, FieldCache.ByteParser parser, java.lang.Byte lowerVal, java.lang.Byte upperVal, boolean includeLower, boolean includeUpper)
Deprecated.Creates a numeric range filter usingFieldCache.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 tonull.
-
newShortRange
@Deprecated public static FieldCacheRangeFilter<java.lang.Short> newShortRange(java.lang.String field, java.lang.Short lowerVal, java.lang.Short upperVal, boolean includeLower, boolean includeUpper)
Deprecated.Creates a numeric range filter usingFieldCache.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 tonull.
-
newShortRange
@Deprecated public static FieldCacheRangeFilter<java.lang.Short> newShortRange(java.lang.String field, FieldCache.ShortParser parser, java.lang.Short lowerVal, java.lang.Short upperVal, boolean includeLower, boolean includeUpper)
Deprecated.Creates a numeric range filter usingFieldCache.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 tonull.
-
newIntRange
public static FieldCacheRangeFilter<java.lang.Integer> newIntRange(java.lang.String field, java.lang.Integer lowerVal, java.lang.Integer upperVal, boolean includeLower, boolean includeUpper)
Creates a numeric range filter usingFieldCache.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 tonull.
-
newIntRange
public static FieldCacheRangeFilter<java.lang.Integer> newIntRange(java.lang.String field, FieldCache.IntParser parser, java.lang.Integer lowerVal, java.lang.Integer upperVal, boolean includeLower, boolean includeUpper)
Creates a numeric range filter usingFieldCache.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 tonull.
-
newLongRange
public static FieldCacheRangeFilter<java.lang.Long> newLongRange(java.lang.String field, java.lang.Long lowerVal, java.lang.Long upperVal, boolean includeLower, boolean includeUpper)
Creates a numeric range filter usingFieldCache.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 tonull.
-
newLongRange
public static FieldCacheRangeFilter<java.lang.Long> newLongRange(java.lang.String field, FieldCache.LongParser parser, java.lang.Long lowerVal, java.lang.Long upperVal, boolean includeLower, boolean includeUpper)
Creates a numeric range filter usingFieldCache.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 tonull.
-
newFloatRange
public static FieldCacheRangeFilter<java.lang.Float> newFloatRange(java.lang.String field, java.lang.Float lowerVal, java.lang.Float upperVal, boolean includeLower, boolean includeUpper)
Creates a numeric range filter usingFieldCache.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 tonull.
-
newFloatRange
public static FieldCacheRangeFilter<java.lang.Float> newFloatRange(java.lang.String field, FieldCache.FloatParser parser, java.lang.Float lowerVal, java.lang.Float upperVal, boolean includeLower, boolean includeUpper)
Creates a numeric range filter usingFieldCache.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 tonull.
-
newDoubleRange
public static FieldCacheRangeFilter<java.lang.Double> newDoubleRange(java.lang.String field, java.lang.Double lowerVal, java.lang.Double upperVal, boolean includeLower, boolean includeUpper)
Creates a numeric range filter usingFieldCache.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 tonull.
-
newDoubleRange
public static FieldCacheRangeFilter<java.lang.Double> newDoubleRange(java.lang.String field, FieldCache.DoubleParser parser, java.lang.Double lowerVal, java.lang.Double upperVal, boolean includeLower, boolean includeUpper)
Creates a numeric range filter usingFieldCache.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 tonull.
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
getField
public java.lang.String getField()
Returns the field name for this filter
-
includesLower
public boolean includesLower()
Returnstrueif the lower endpoint is inclusive
-
includesUpper
public boolean includesUpper()
Returnstrueif 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 (nullforTisString}
-
-