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

Package org.apache.lucene.search

# Class SortedNumericSortField

java.lang.Object
org.apache.lucene.search.SortField
org.apache.lucene.search.SortedNumericSortField

public class SortedNumericSortField extends SortField
SortField for `SortedNumericDocValues`.

A SortedNumericDocValues contains multiple values for a field, so sorting with this technique "selects" a value as the representative sort value for the document.

By default, the minimum value in the list is selected as the sort value, but this can be customized.

Like sorting by string, this also supports sorting missing values as first or last, via `setMissingValue(Object)`.

See Also:
  - `SortedNumericSelector`

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static final class`
  `SortedNumericSortField.Provider`
  A SortFieldProvider for this sort field

  ## Nested classes/interfaces inherited from class org.apache.lucene.search.SortField

  `SortField.Type`

- ## Field Summary

  ### Fields inherited from class org.apache.lucene.search.SortField

  `FIELD_DOC, FIELD_SCORE, missingValue, reverse, STRING_FIRST, STRING_LAST`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SortedNumericSortField(String field, SortField.Type type)`
  Creates a sort, by the minimum value in the set for the document.
  `SortedNumericSortField(String field, SortField.Type type, boolean reverse)`
  Creates a sort, possibly in reverse, by the minimum value in the set for the document.
  `SortedNumericSortField(String field, SortField.Type type, boolean reverse, SortedNumericSelector.Type selector)`
  Creates a sort, possibly in reverse, specifying how the sort value from the document's set is selected.
  `SortedNumericSortField(String field, SortField.Type type, boolean reverse, SortedNumericSelector.Type selector, Object missingValue)`
  Creates a sort, possibly in reverse, specifying how the sort value from the document's set is selected.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object obj)`
  Returns true if `o` is equal to this.
  `FieldComparator<?>`
  `getComparator(int numHits, Pruning pruning)`
  Returns the `FieldComparator` to use for sorting.
  `IndexSorter`
  `getIndexSorter()`
  Returns an `IndexSorter` used for sorting index segments by this SortField.
  `SortField.Type`
  `getNumericType()`
  Returns the numeric type in use for this sort
  `SortedNumericSelector.Type`
  `getSelector()`
  Returns the selector in use for this sort
  `int`
  `hashCode()`
  Returns a hash code for this `SortField` instance.
  `void`
  `setMissingValue(Object missingValue)`
  Set the value to use for documents that don't have a value.
  `String`
  `toString()`

  ### Methods inherited from class org.apache.lucene.search.SortField

  `getComparatorSource, getField, getMissingValue, getOptimizeSortWithIndexedData, getOptimizeSortWithPoints, getReverse, getType, needsScores, readType, rewrite, setOptimizeSortWithIndexedData, setOptimizeSortWithPoints`

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

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

- ## Constructor Details

  - ### SortedNumericSortField

    public SortedNumericSortField(String field, SortField.Type type)
    Creates a sort, by the minimum value in the set for the document.
    Parameters:
      `field` - Name of field to sort by. Must not be null.
      `type` - Type of values

  - ### SortedNumericSortField

    public SortedNumericSortField(String field, SortField.Type type, boolean reverse)
    Creates a sort, possibly in reverse, by the minimum value in the set for the document.
    Parameters:
      `field` - Name of field to sort by. Must not be null.
      `type` - Type of values
      `reverse` - True if natural order should be reversed.

  - ### SortedNumericSortField

    public SortedNumericSortField(String field, SortField.Type type, boolean reverse, SortedNumericSelector.Type selector)
    Creates a sort, possibly in reverse, specifying how the sort value from the document's set is selected.
    Parameters:
      `field` - Name of field to sort by. Must not be null.
      `type` - Type of values
      `reverse` - True if natural order should be reversed.
      `selector` - custom selector type for choosing the sort value from the set.

  - ### SortedNumericSortField

    public SortedNumericSortField(String field, SortField.Type type, boolean reverse, SortedNumericSelector.Type selector, Object missingValue)
    Creates a sort, possibly in reverse, specifying how the sort value from the document's set is selected.
    Parameters:
      `field` - Name of field to sort by. Must not be null.
      `type` - Type of values
      `reverse` - True if natural order should be reversed.
      `selector` - custom selector type for choosing the sort value from the set.
      `missingValue` - the sort value to use for documents with no value in the field

- ## Method Details

  - ### getNumericType

    public SortField.Type getNumericType()
    Returns the numeric type in use for this sort

  - ### getSelector

    public SortedNumericSelector.Type getSelector()
    Returns the selector in use for this sort

  - ### hashCode

    public int hashCode()
    Description copied from class: `SortField`
    Returns a hash code for this `SortField` instance. If a `FieldComparatorSource` was provided, it must properly implement hashCode (unless a singleton is always used).
    Overrides:
      `hashCode` in class `SortField`

  - ### equals

    public boolean equals(Object obj)
    Description copied from class: `SortField`
    Returns true if `o` is equal to this. If a `FieldComparatorSource` was provided, it must properly implement equals (unless a singleton is always used).
    Overrides:
      `equals` in class `SortField`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `SortField`

  - ### setMissingValue

    public void setMissingValue(Object missingValue)
    Description copied from class: `SortField`
    Set the value to use for documents that don't have a value.
    Overrides:
      `setMissingValue` in class `SortField`

  - ### getComparator

    public FieldComparator<?> getComparator(int numHits, Pruning pruning)
    Description copied from class: `SortField`
    Returns the `FieldComparator` to use for sorting.
    Overrides:
      `getComparator` in class `SortField`
    Parameters:
      `numHits` - number of top hits the queue will store
      `pruning` - controls how can the comparator to skip documents via `LeafFieldComparator.competitiveIterator()`
    Returns:
      `FieldComparator` to use when sorting

  - ### getIndexSorter

    public IndexSorter getIndexSorter()
    Description copied from class: `SortField`
    Returns an `IndexSorter` used for sorting index segments by this SortField.

    If the SortField cannot be used for index sorting (for example, if it uses scores or other query-dependent values) then this method should return `null`

    SortFields that implement this method should also implement a companion `SortFieldProvider` to serialize and deserialize the sort in index segment headers

    Overrides:
      `getIndexSorter` in class `SortField`