Package org.apache.lucene.search
Class TermRangeFilter
- java.lang.Object
-
- org.apache.lucene.search.Filter
-
- org.apache.lucene.search.MultiTermQueryWrapperFilter<TermRangeQuery>
-
- org.apache.lucene.search.TermRangeFilter
-
- All Implemented Interfaces:
Serializable
public class TermRangeFilter extends MultiTermQueryWrapperFilter<TermRangeQuery>
A Filter that restricts search results to a range of term values in a given field.This filter matches the documents looking for terms that fall into the supplied range according to
String.compareTo(String)
, unless aCollator
is provided. It is not intended for numerical ranges; useNumericRangeFilter
instead.If you construct a large number of range filters with different ranges but on the same field,
FieldCacheRangeFilter
may have significantly better performance.- Since:
- 2.9
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.apache.lucene.search.MultiTermQueryWrapperFilter
query
-
-
Constructor Summary
Constructors Constructor Description TermRangeFilter(String fieldName, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper)
TermRangeFilter(String fieldName, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper, Collator collator)
WARNING: Using this constructor and supplying a non-null value in thecollator
parameter will cause every single index Term in the Field referenced by lowerTerm and/or upperTerm to be examined.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Collator
getCollator()
Returns the collator used to determine range inclusion, if any.String
getField()
Returns the field name for this filterString
getLowerTerm()
Returns the lower value of this range filterString
getUpperTerm()
Returns the upper value of this range filterboolean
includesLower()
Returnstrue
if the lower endpoint is inclusiveboolean
includesUpper()
Returnstrue
if the upper endpoint is inclusivestatic TermRangeFilter
Less(String fieldName, String upperTerm)
Constructs a filter for fieldfieldName
matching less than or equal toupperTerm
.static TermRangeFilter
More(String fieldName, String lowerTerm)
Constructs a filter for fieldfieldName
matching greater than or equal tolowerTerm
.-
Methods inherited from class org.apache.lucene.search.MultiTermQueryWrapperFilter
clearTotalNumberOfTerms, equals, getDocIdSet, getTotalNumberOfTerms, hashCode, toString
-
-
-
-
Constructor Detail
-
TermRangeFilter
public TermRangeFilter(String fieldName, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper)
- Parameters:
fieldName
- The field this range applies tolowerTerm
- The lower bound on this rangeupperTerm
- The upper bound on this rangeincludeLower
- Does this range include the lower bound?includeUpper
- Does this range include the upper bound?- Throws:
IllegalArgumentException
- if both terms are null or if lowerTerm is null and includeLower is true (similar for upperTerm and includeUpper)
-
TermRangeFilter
public TermRangeFilter(String fieldName, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper, Collator collator)
WARNING: Using this constructor and supplying a non-null value in thecollator
parameter will cause every single index Term in the Field referenced by lowerTerm and/or upperTerm to be examined. Depending on the number of index Terms in this Field, the operation could be very slow.- Parameters:
lowerTerm
- The lower bound on this rangeupperTerm
- The upper bound on this rangeincludeLower
- Does this range include the lower bound?includeUpper
- Does this range include the upper bound?collator
- The collator to use when determining range inclusion; set to null to use Unicode code point ordering instead of collation.- Throws:
IllegalArgumentException
- if both terms are null or if lowerTerm is null and includeLower is true (similar for upperTerm and includeUpper)
-
-
Method Detail
-
Less
public static TermRangeFilter Less(String fieldName, String upperTerm)
Constructs a filter for fieldfieldName
matching less than or equal toupperTerm
.
-
More
public static TermRangeFilter More(String fieldName, String lowerTerm)
Constructs a filter for fieldfieldName
matching greater than or equal tolowerTerm
.
-
getField
public String getField()
Returns the field name for this filter
-
getLowerTerm
public String getLowerTerm()
Returns the lower value of this range filter
-
getUpperTerm
public String getUpperTerm()
Returns the upper value of this range filter
-
includesLower
public boolean includesLower()
Returnstrue
if the lower endpoint is inclusive
-
includesUpper
public boolean includesUpper()
Returnstrue
if the upper endpoint is inclusive
-
getCollator
public Collator getCollator()
Returns the collator used to determine range inclusion, if any.
-
-