Class IntField

java.lang.Object
org.apache.lucene.document.Field
org.apache.lucene.document.IntField
All Implemented Interfaces:
IndexableField

public final class IntField extends Field
Field that stores a per-document int value for scoring, sorting or value retrieval and index the field for fast range filters. If you need more fine-grained control you can use IntPoint, NumericDocValuesField or SortedNumericDocValuesField, and StoredField.

This field defines static factory methods for creating common queries:

See Also:
  • Constructor Details

    • IntField

      @Deprecated public IntField(String name, int value)
      Deprecated.
      Creates a new IntField, indexing the provided point and storing it as a DocValue.
      Parameters:
      name - field name
      value - the int value
      Throws:
      IllegalArgumentException - if the field name or value is null.
    • IntField

      public IntField(String name, int value, Field.Store stored)
      Creates a new IntField, indexing the provided point, storing it as a DocValue, and optionally storing it as a stored field.
      Parameters:
      name - field name
      value - the int value
      stored - whether to store the field
      Throws:
      IllegalArgumentException - if the field name or value is null.
  • Method Details

    • binaryValue

      public BytesRef binaryValue()
      Description copied from interface: IndexableField
      Non-null if this field has a binary value
      Specified by:
      binaryValue in interface IndexableField
      Overrides:
      binaryValue in class Field
    • storedValue

      public StoredValue storedValue()
      Description copied from interface: IndexableField
      Stored value. This method is called to populate stored fields and must return a non-null value if the field stored.
      Specified by:
      storedValue in interface IndexableField
      Overrides:
      storedValue in class Field
    • setIntValue

      public void setIntValue(int value)
      Description copied from class: Field
      Expert: change the value of this field. See Field.setStringValue(String).
      Overrides:
      setIntValue in class Field
    • toString

      public String toString()
      Description copied from class: Field
      Prints a Field for human consumption.
      Overrides:
      toString in class Field
    • newExactQuery

      public static Query newExactQuery(String field, int value)
      Create a query for matching an exact integer value.
      Parameters:
      field - field name. must not be null.
      value - exact value
      Returns:
      a query matching documents with this exact value
      Throws:
      IllegalArgumentException - if field is null.
    • newRangeQuery

      public static Query newRangeQuery(String field, int lowerValue, int upperValue)
      Create a range query for integer values.

      You can have half-open ranges (which are in fact </≤ or >/≥ queries) by setting lowerValue = Integer.MIN_VALUE or upperValue = Integer.MAX_VALUE.

      Ranges are inclusive. For exclusive ranges, pass Math.addExact(lowerValue, 1) or Math.addExact(upperValue, -1).

      Parameters:
      field - field name. must not be null.
      lowerValue - lower portion of the range (inclusive).
      upperValue - upper portion of the range (inclusive).
      Returns:
      a query matching documents within this range.
      Throws:
      IllegalArgumentException - if field is null.
    • newSetQuery

      public static Query newSetQuery(String field, int... values)
      Create a query matching values in a supplied set
      Parameters:
      field - field name. must not be null.
      values - integer values
      Returns:
      a query matching documents within this set.
      Throws:
      IllegalArgumentException - if field is null.
    • newSortField

      public static SortField newSortField(String field, boolean reverse, SortedNumericSelector.Type selector)
      Create a new SortField for int values.
      Parameters:
      field - field name. must not be null.
      reverse - true if natural order should be reversed.
      selector - custom selector type for choosing the sort value from the set.