org.apache.lucene.search

## Class DoubleValuesSource

- java.lang.Object
- - org.apache.lucene.search.DoubleValuesSource

-     public abstract class DoubleValuesSource
      extends Object

  Base class for producing `DoubleValues` To obtain a `DoubleValues` object for a leaf reader, clients should call `getValues(LeafReaderContext, DoubleValues)`. DoubleValuesSource objects for NumericDocValues fields can be obtained by calling `fromDoubleField(String)`, `fromFloatField(String)`, `fromIntField(String)` or `fromLongField(String)`, or from `fromField(String, LongToDoubleFunction)` if special long-to-double encoding is required. Scores may be used as a source for value calculations by wrapping a `Scorer` using `fromScorer(Scorer)` and passing the resulting DoubleValues to `getValues(LeafReaderContext, DoubleValues)`. The scores can then be accessed using the `SCORES` DoubleValuesSource.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static DoubleValuesSource` | `SCORES` A DoubleValuesSource that exposes a document's score If this source is used as part of a values calculation, then callers must not pass `null` as the `DoubleValues` parameter on `getValues(LeafReaderContext, DoubleValues)`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DoubleValuesSource()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static DoubleValuesSource` | `constant(double value)` Creates a DoubleValuesSource that always returns a constant value
    `static DoubleValuesSource` | `fromDoubleField(String field)` Creates a DoubleValuesSource that wraps a double-valued field
    `static DoubleValuesSource` | `fromField(String field, LongToDoubleFunction decoder)` Creates a DoubleValuesSource that wraps a generic NumericDocValues field
    `static DoubleValuesSource` | `fromFloatField(String field)` Creates a DoubleValuesSource that wraps a float-valued field
    `static DoubleValuesSource` | `fromIntField(String field)` Creates a DoubleValuesSource that wraps an int-valued field
    `static DoubleValuesSource` | `fromLongField(String field)` Creates a DoubleValuesSource that wraps a long-valued field
    `static DoubleValues` | `fromScorer(Scorer scorer)` Returns a DoubleValues instance that wraps scores returned by a Scorer
    `static DoubleValuesSource` | `function(DoubleValuesSource in, DoubleUnaryOperator function)` Creates a DoubleValuesSource that is a function of another DoubleValuesSource
    `SortField` | `getSortField(boolean reverse)` Create a sort field based on the value of this producer
    `abstract DoubleValues` | `getValues(LeafReaderContext ctx, DoubleValues scores)` Returns a `DoubleValues` instance for the passed-in LeafReaderContext and scores If scores are not needed to calculate the values (ie `returns false`, callers may safely pass `null` for the `scores` parameter.
    `abstract boolean` | `needsScores()` Return true if document scores are needed to calculate values
    `static DoubleValuesSource` | `scoringFunction(DoubleValuesSource in, ToDoubleBiFunction<Double,Double> function)` Creates a DoubleValuesSource that is a function of another DoubleValuesSource and a score
    `LongValuesSource` | `toLongValuesSource()` Convert to a LongValuesSource by casting the double values to longs

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

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

- - ### Field Detail

    - #### SCORES

          public static final DoubleValuesSource SCORES

      A DoubleValuesSource that exposes a document's score If this source is used as part of a values calculation, then callers must not pass `null` as the `DoubleValues` parameter on `getValues(LeafReaderContext, DoubleValues)`

  - ### Constructor Detail

    - #### DoubleValuesSource

          public DoubleValuesSource()

  - ### Method Detail

    - #### getValues

          public abstract DoubleValues getValues(LeafReaderContext ctx,
                                                 DoubleValues scores)
                                          throws IOException

      Returns a `DoubleValues` instance for the passed-in LeafReaderContext and scores If scores are not needed to calculate the values (ie `returns false`, callers may safely pass `null` for the `scores` parameter.
      Throws:
        `IOException`

    - #### needsScores

          public abstract boolean needsScores()

      Return true if document scores are needed to calculate values

    - #### getSortField

          public SortField getSortField(boolean reverse)

      Create a sort field based on the value of this producer
      Parameters:
        `reverse` - true if the sort should be decreasing

    - #### toLongValuesSource

          public final LongValuesSource toLongValuesSource()

      Convert to a LongValuesSource by casting the double values to longs

    - #### fromField

          public static DoubleValuesSource fromField(String field,
                                                     LongToDoubleFunction decoder)

      Creates a DoubleValuesSource that wraps a generic NumericDocValues field
      Parameters:
        `field` - the field to wrap, must have NumericDocValues
        `decoder` - a function to convert the long-valued doc values to doubles

    - #### fromDoubleField

          public static DoubleValuesSource fromDoubleField(String field)

      Creates a DoubleValuesSource that wraps a double-valued field

    - #### fromFloatField

          public static DoubleValuesSource fromFloatField(String field)

      Creates a DoubleValuesSource that wraps a float-valued field

    - #### fromLongField

          public static DoubleValuesSource fromLongField(String field)

      Creates a DoubleValuesSource that wraps a long-valued field

    - #### fromIntField

          public static DoubleValuesSource fromIntField(String field)

      Creates a DoubleValuesSource that wraps an int-valued field

    - #### constant

          public static DoubleValuesSource constant(double value)

      Creates a DoubleValuesSource that always returns a constant value

    - #### function

          public static DoubleValuesSource function(DoubleValuesSource in,
                                                    DoubleUnaryOperator function)

      Creates a DoubleValuesSource that is a function of another DoubleValuesSource

    - #### scoringFunction

          public static DoubleValuesSource scoringFunction(DoubleValuesSource in,
                                                           ToDoubleBiFunction<Double,Double> function)

      Creates a DoubleValuesSource that is a function of another DoubleValuesSource and a score
      Parameters:
        `in` - the DoubleValuesSource to use as an input
        `function` - a function of the form (source, score) == result

    - #### fromScorer

          public static DoubleValues fromScorer(Scorer scorer)

      Returns a DoubleValues instance that wraps scores returned by a Scorer

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