IndexSorter.ComparableValues (Lucene 10.5.0 core API)
Description: declaration: package: org.apache.lucene.index, interface: IndexSorter, interface: ComparableValues

Package org.apache.lucene.index

# Interface IndexSorter.ComparableValues

Enclosing interface:
  `IndexSorter`

public static interface IndexSorter.ComparableValues
Caches the sort value of the current document of every segment being merged, and compares them.

This is the merge-sort counterpart of `IndexSorter.DocComparator`. Most sorts reduce a document to a single sortable `long` and should implement `IndexSorter.getComparableProviders(List)` instead; the `fromComparableProviders(org.apache.lucene.index.IndexSorter.ComparableProvider[])` adapter exposes them through this interface with no change in behaviour. Sorts whose value cannot be represented as a `long` (for example raw bytes) implement `IndexSorter.getComparableValues(List)` directly.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `compare(int readerIndexA, int readerIndexB)`
  Compares the values previously read by `setTopValue(int, int)` for the two segments.
  `static IndexSorter.ComparableValues`
  `fromComparableProviders(IndexSorter.ComparableProvider[] providers)`
  Adapts an array of `IndexSorter.ComparableProvider` (one per segment) to `IndexSorter.ComparableValues`
  `void`
  `setTopValue(int readerIndex, int docID)`
  Reads the value of the current document of the given segment so that it can later be compared by `compare(int, int)`.

- ## Method Details

  - ### setTopValue

    void setTopValue(int readerIndex, int docID) throws IOException
    Reads the value of the current document of the given segment so that it can later be compared by `compare(int, int)`.

    The merge sort visits the documents of each segment in increasing docID order, so `docID` is non-decreasing for a given `readerIndex` between consecutive calls.

    Parameters:
      `readerIndex` - the index of the segment in the list passed to `IndexSorter.getComparableValues(List)`
      `docID` - the document whose value should be read
    Throws:
      `IOException`

  - ### compare

    int compare(int readerIndexA, int readerIndexB)
    Compares the values previously read by `setTopValue(int, int)` for the two segments. The returned value follows the same contract as `Comparator.compare(Object, Object)`, without applying the `reverse` flag (the caller is responsible for that).

  - ### fromComparableProviders

    static IndexSorter.ComparableValues fromComparableProviders(IndexSorter.ComparableProvider[] providers)
    Adapts an array of `IndexSorter.ComparableProvider` (one per segment) to `IndexSorter.ComparableValues`