Package org.apache.lucene.index

# Class SortingCodecReader

java.lang.Object
org.apache.lucene.index.IndexReader
org.apache.lucene.index.LeafReader
org.apache.lucene.index.CodecReader
org.apache.lucene.index.FilterCodecReader
org.apache.lucene.index.SortingCodecReader

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`

public final class SortingCodecReader extends FilterCodecReader
An `CodecReader` which supports sorting documents by a given `Sort`. This can be used to re-sort and index after it's been created by wrapping all readers of the index with this reader and adding it to a fresh IndexWriter via `IndexWriter.addIndexes(CodecReader...)`. NOTE: This reader should only be used for merging. Pulling fields from this reader might be very costly and memory intensive.

WARNING: This API is experimental and might change in incompatible ways in the next release.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `SortingCodecReader.SortingValuesIterator`
  Iterator over KnnVectorValues accepting a mapping to differently-sorted docs.

  ## Nested classes/interfaces inherited from class org.apache.lucene.index.IndexReader

  `IndexReader.CacheHelper, IndexReader.CacheKey, IndexReader.ClosedListener`

- ## Field Summary

  ### Fields inherited from class org.apache.lucene.index.FilterCodecReader

  `in`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `IndexReader.CacheHelper`
  `getCoreCacheHelper()`
  Optional method: Return a `IndexReader.CacheHelper` that can be used to cache based on the content of this leaf regardless of deletions.
  `DocValuesProducer`
  `getDocValuesReader()`
  Expert: retrieve underlying DocValuesProducer
  `StoredFieldsReader`
  `getFieldsReader()`
  Expert: retrieve underlying StoredFieldsReader
  `Bits`
  `getLiveDocs()`
  Returns the `Bits` representing live (not deleted) docs.
  `LeafMetaData`
  `getMetaData()`
  Return metadata about this leaf.
  `NormsProducer`
  `getNormsReader()`
  Expert: retrieve underlying NormsProducer
  `PointsReader`
  `getPointsReader()`
  Expert: retrieve underlying PointsReader
  `FieldsProducer`
  `getPostingsReader()`
  Expert: retrieve underlying FieldsProducer
  `IndexReader.CacheHelper`
  `getReaderCacheHelper()`
  Optional method: Return a `IndexReader.CacheHelper` that can be used to cache based on the content of this reader.
  `TermVectorsReader`
  `getTermVectorsReader()`
  Expert: retrieve underlying TermVectorsReader
  `KnnVectorsReader`
  `getVectorReader()`
  Expert: retrieve underlying VectorReader
  `static org.apache.lucene.index.SortingCodecReader.SortingIteratorSupplier`
  `iteratorSupplier(KnnVectorValues values, Sorter.DocMap docMap)`
  Creates a factory for SortingValuesIterator.
  `String`
  `toString()`
  `static CodecReader`
  `wrap(CodecReader reader, Sorter.DocMap docMap, Sort sort)`
  Expert: same as `wrap(org.apache.lucene.index.CodecReader, Sort)` but operates directly on a `Sorter.DocMap`.
  `static CodecReader`
  `wrap(CodecReader reader, Sort sort)`
  Return a sorted view of `reader` according to the order defined by `sort` .

  ### Methods inherited from class org.apache.lucene.index.FilterCodecReader

  `checkIntegrity, doClose, getDelegate, getFieldInfos, maxDoc, numDocs, unwrap`

  ### Methods inherited from class org.apache.lucene.index.CodecReader

  `getBinaryDocValues, getByteVectorValues, getDocValuesSkipper, getFloatVectorValues, getNormValues, getNumericDocValues, getPointValues, getSortedDocValues, getSortedNumericDocValues, getSortedSetDocValues, searchNearestVectors, searchNearestVectors, storedFields, terms, termVectors`

  ### Methods inherited from class org.apache.lucene.index.LeafReader

  `docFreq, getContext, getDocCount, getSumDocFreq, getSumTotalTermFreq, postings, postings, searchNearestVectors, searchNearestVectors, totalTermFreq`

  ### Methods inherited from class org.apache.lucene.index.IndexReader

  `close, decRef, ensureOpen, equals, getRefCount, hasDeletions, hashCode, incRef, leaves, notifyReaderClosedListeners, numDeletedDocs, registerParentReader, tryIncRef`

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

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

- ## Method Details

  - ### iteratorSupplier

    public static org.apache.lucene.index.SortingCodecReader.SortingIteratorSupplier iteratorSupplier(KnnVectorValues values, Sorter.DocMap docMap) throws IOException
    Creates a factory for SortingValuesIterator. Does the work of computing the (new docId to old ordinal) mapping, and caches the result, enabling it to create new iterators cheaply.
    Parameters:
      `values` - the values over which to iterate
      `docMap` - the mapping from "old" docIds to "new" (sorted) docIds.
    Throws:
      `IOException`

  - ### wrap

    public static CodecReader wrap(CodecReader reader, Sort sort) throws IOException
    Return a sorted view of `reader` according to the order defined by `sort` . If the reader is already sorted, this method might return the reader as-is.
    Throws:
      `IOException`

  - ### wrap

    public static CodecReader wrap(CodecReader reader, Sorter.DocMap docMap, Sort sort)
    Expert: same as `wrap(org.apache.lucene.index.CodecReader, Sort)` but operates directly on a `Sorter.DocMap`.

  - ### getPostingsReader

    public FieldsProducer getPostingsReader()
    Description copied from class: `CodecReader`
    Expert: retrieve underlying FieldsProducer
    Overrides:
      `getPostingsReader` in class `FilterCodecReader`

  - ### getFieldsReader

    public StoredFieldsReader getFieldsReader()
    Description copied from class: `CodecReader`
    Expert: retrieve underlying StoredFieldsReader
    Overrides:
      `getFieldsReader` in class `FilterCodecReader`

  - ### getLiveDocs

    public Bits getLiveDocs()
    Description copied from class: `LeafReader`
    Returns the `Bits` representing live (not deleted) docs. A set bit indicates the doc ID has not been deleted. If this method returns null it means there are no deleted documents (all documents are live).

    The returned instance has been safely published for use by multiple threads without additional synchronization.

    Overrides:
      `getLiveDocs` in class `FilterCodecReader`

  - ### getPointsReader

    public PointsReader getPointsReader()
    Description copied from class: `CodecReader`
    Expert: retrieve underlying PointsReader
    Overrides:
      `getPointsReader` in class `FilterCodecReader`

  - ### getVectorReader

    public KnnVectorsReader getVectorReader()
    Description copied from class: `CodecReader`
    Expert: retrieve underlying VectorReader
    Overrides:
      `getVectorReader` in class `FilterCodecReader`

  - ### getNormsReader

    public NormsProducer getNormsReader()
    Description copied from class: `CodecReader`
    Expert: retrieve underlying NormsProducer
    Overrides:
      `getNormsReader` in class `FilterCodecReader`

  - ### getDocValuesReader

    public DocValuesProducer getDocValuesReader()
    Description copied from class: `CodecReader`
    Expert: retrieve underlying DocValuesProducer
    Overrides:
      `getDocValuesReader` in class `FilterCodecReader`

  - ### getTermVectorsReader

    public TermVectorsReader getTermVectorsReader()
    Description copied from class: `CodecReader`
    Expert: retrieve underlying TermVectorsReader
    Overrides:
      `getTermVectorsReader` in class `FilterCodecReader`

  - ### toString

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

  - ### getCoreCacheHelper

    public IndexReader.CacheHelper getCoreCacheHelper()
    Description copied from class: `LeafReader`
    Optional method: Return a `IndexReader.CacheHelper` that can be used to cache based on the content of this leaf regardless of deletions. Two readers that have the same data but different sets of deleted documents or doc values updates may be considered equal. Consider using `IndexReader.getReaderCacheHelper()` if you need deletions or dv updates to be taken into account.

    A return value of `null` indicates that this reader is not suited for caching, which is typically the case for short-lived wrappers that alter the content of the wrapped leaf reader.

    Specified by:
      `getCoreCacheHelper` in class `LeafReader`

  - ### getReaderCacheHelper

    public IndexReader.CacheHelper getReaderCacheHelper()
    Description copied from class: `IndexReader`
    Optional method: Return a `IndexReader.CacheHelper` that can be used to cache based on the content of this reader. Two readers that have different data or different sets of deleted documents will be considered different.

    A return value of `null` indicates that this reader is not suited for caching, which is typically the case for short-lived wrappers that alter the content of the wrapped reader.

    Specified by:
      `getReaderCacheHelper` in class `IndexReader`

  - ### getMetaData

    public LeafMetaData getMetaData()
    Description copied from class: `LeafReader`
    Return metadata about this leaf.
    Overrides:
      `getMetaData` in class `FilterCodecReader`