DoubleField (Lucene 10.5.0 core API)
Description: declaration: package: org.apache.lucene.document, class: DoubleField

Package org.apache.lucene.document

# Class DoubleField

java.lang.Object
org.apache.lucene.document.Field
org.apache.lucene.document.DoubleField

All Implemented Interfaces:
  `IndexableField`

public final class DoubleField extends Field
Field that stores a per-document `double` 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 `DoublePoint`, `DoubleDocValuesField` and `StoredField`.

This field defines static factory methods for creating common queries:

- `newExactQuery(String, double)` for matching an exact 1D point.
- `newRangeQuery(String, double, double)` for matching a 1D range.
- `newSetQuery(String, double...)` for matching a 1D set.

See Also:
  - `PointValues`

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class org.apache.lucene.document.Field

  `Field.Store`

- ## Field Summary

  ### Fields inherited from class org.apache.lucene.document.Field

  `fieldsData, name, type`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DoubleField(String name, double value, Field.Store stored)`
  Creates a new DoubleField, indexing the provided point, storing it as a DocValue, and optionally storing it as a stored field.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `BytesRef`
  `binaryValue()`
  Non-null if this field has a binary value
  `static Query`
  `newExactQuery(String field, double value)`
  Create a query for matching an exact double value.
  `static Query`
  `newRangeQuery(String field, double lowerValue, double upperValue)`
  Create a range query for double values.
  `static Query`
  `newSetQuery(String field, double... values)`
  Create a query matching values in a supplied set
  `static SortField`
  `newSortField(String field, boolean reverse, SortedNumericSelector.Type selector)`
  Create a new `SortField` for double values.
  `static SortField`
  `newSortField(String field, boolean reverse, SortedNumericSelector.Type selector, double missingValue)`
  Create a new `SortField` for double values.
  `void`
  `setDoubleValue(double value)`
  Expert: change the value of this field.
  `void`
  `setLongValue(long value)`
  Expert: change the value of this field.
  `StoredValue`
  `storedValue()`
  Stored value.
  `String`
  `toString()`
  Prints a Field for human consumption.

  ### Methods inherited from class org.apache.lucene.document.Field

  `fieldType, getCharSequenceValue, invertableType, name, numericValue, readerValue, setBytesValue, setBytesValue, setByteValue, setFloatValue, setIntValue, setReaderValue, setShortValue, setStringValue, setTokenStream, stringValue, tokenStream, tokenStreamValue`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### DoubleField

    public DoubleField(String name, double value, Field.Store stored)
    Creates a new DoubleField, indexing the provided point, storing it as a DocValue, and optionally storing it as a stored field.
    Parameters:
      `name` - field name
      `value` - the double 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`

  - ### toString

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

  - ### setDoubleValue

    public void setDoubleValue(double value)
    Description copied from class: `Field`
    Expert: change the value of this field. See `Field.setStringValue(String)`.
    Overrides:
      `setDoubleValue` in class `Field`

  - ### setLongValue

    public void setLongValue(long value)
    Description copied from class: `Field`
    Expert: change the value of this field. See `Field.setStringValue(String)`.
    Overrides:
      `setLongValue` in class `Field`

  - ### newExactQuery

    public static Query newExactQuery(String field, double value)
    Create a query for matching an exact double 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, double lowerValue, double upperValue)
    Create a range query for double values.

    You can have half-open ranges (which are in fact </≤ or >/≥ queries) by setting `lowerValue = Double.NEGATIVE_INFINITY` or `upperValue = Double.POSITIVE_INFINITY`.

    Range comparisons are consistent with `Double.compareTo(Double)`.

    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, double... values)
    Create a query matching values in a supplied set
    Parameters:
      `field` - field name. must not be `null`.
      `values` - double 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 double 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.

  - ### newSortField

    public static SortField newSortField(String field, boolean reverse, SortedNumericSelector.Type selector, double missingValue)
    Create a new `SortField` for double 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.
      `missingValue` - a sort value to use for documents with no value in the field