## org.apache.lucene.search
Class TermRangeFilter

    java.lang.Object
      org.apache.lucene.search.Filter
          org.apache.lucene.search.MultiTermQueryWrapperFilter
              org.apache.lucene.search.TermRangeFilter

All Implemented Interfaces:
  java.io.Serializable

    public class TermRangeFilter

extends MultiTermQueryWrapperFilter

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 a `Collator` is provided. It is not intended for numerical ranges; use `NumericRangeFilter` 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
`TermRangeFilter(java.lang.String fieldName, java.lang.String lowerTerm, java.lang.String upperTerm, boolean includeLower, boolean includeUpper)`
`TermRangeFilter(java.lang.String fieldName, java.lang.String lowerTerm, java.lang.String upperTerm, boolean includeLower, boolean includeUpper, java.text.Collator collator)` WARNING: Using this constructor and supplying a non-null value in the `collator` parameter will cause every single index Term in the Field referenced by lowerTerm and/or upperTerm to be examined.

Method Summary
`java.text.Collator` `getCollator()` Returns the collator used to determine range inclusion, if any.
`java.lang.String` `getField()` Returns the field name for this filter
`java.lang.String` `getLowerTerm()` Returns the lower value of this range filter
`java.lang.String` `getUpperTerm()` Returns the upper value of this range filter
`boolean` `includesLower()` Returns `true` if the lower endpoint is inclusive
`boolean` `includesUpper()` Returns `true` if the upper endpoint is inclusive
`static TermRangeFilter` `Less(java.lang.String fieldName, java.lang.String upperTerm)` Constructs a filter for field `fieldName` matching less than or equal to `upperTerm`.
`static TermRangeFilter` `More(java.lang.String fieldName, java.lang.String lowerTerm)` Constructs a filter for field `fieldName` matching greater than or equal to `lowerTerm`.

Methods inherited from class org.apache.lucene.search.MultiTermQueryWrapperFilter
`bits, clearTotalNumberOfTerms, equals, getDocIdSet, getTotalNumberOfTerms, hashCode, toString`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### TermRangeFilter

    public TermRangeFilter(java.lang.String fieldName,
                           java.lang.String lowerTerm,
                           java.lang.String upperTerm,
                           boolean includeLower,
                           boolean includeUpper)

Parameters:
  `fieldName` - The field this range applies to
  `lowerTerm` - The lower bound on this range
  `upperTerm` - The upper bound on this range
  `includeLower` - Does this range include the lower bound?
  `includeUpper` - Does this range include the upper bound?
Throws:
  `java.lang.IllegalArgumentException` - if both terms are null or if lowerTerm is null and includeLower is true (similar for upperTerm and includeUpper)

### TermRangeFilter

    public TermRangeFilter(java.lang.String fieldName,
                           java.lang.String lowerTerm,
                           java.lang.String upperTerm,
                           boolean includeLower,
                           boolean includeUpper,
                           java.text.Collator collator)

  WARNING: Using this constructor and supplying a non-null value in the `collator` 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 range
    `upperTerm` - The upper bound on this range
    `includeLower` - 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:
    `java.lang.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(java.lang.String fieldName,
                                       java.lang.String upperTerm)

  Constructs a filter for field `fieldName` matching less than or equal to `upperTerm`.

### More

    public static TermRangeFilter More(java.lang.String fieldName,
                                       java.lang.String lowerTerm)

  Constructs a filter for field `fieldName` matching greater than or equal to `lowerTerm`.

### getField

    public java.lang.String getField()

  Returns the field name for this filter

### getLowerTerm

    public java.lang.String getLowerTerm()

  Returns the lower value of this range filter

### getUpperTerm

    public java.lang.String getUpperTerm()

  Returns the upper value of this range 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

### getCollator

    public java.text.Collator getCollator()

  Returns the collator used to determine range inclusion, if any.

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