Class Sorter

java.lang.Object
org.apache.lucene.index.sorter.Sorter
Direct Known Subclasses:
BlockJoinSorter, NumericDocValuesSorter

public abstract class Sorter extends Object
Sorts documents of a given index by returning a permutation on the document IDs.

NOTE: A Sorter implementation can be easily written from a document comparator by using the sort(int, DocComparator) helper method. This is especially useful when documents are directly comparable by their field values.

  • Field Details

    • INDEX_ORDER_COMPARATOR

      public static final Sorter.DocComparator INDEX_ORDER_COMPARATOR
      A comparator that keeps documents in index order.
    • REVERSE_DOCS

      public static final Sorter REVERSE_DOCS
      Sorts documents in reverse order. NOTE: This Sorter is not idempotent. Sorting an AtomicReader once or twice will return two different AtomicReader views. This Sorter should not be used with SortingMergePolicy.
  • Constructor Details

    • Sorter

      public Sorter()
  • Method Details

    • sort

      public abstract Sorter.DocMap sort(AtomicReader reader) throws IOException
      Returns a mapping from the old document ID to its new location in the sorted index. Implementations can use the auxiliary sort(int, DocComparator) to compute the old-to-new permutation given a list of documents and their corresponding values.

      A return value of null is allowed and means that reader is already sorted.

      NOTE: deleted documents are expected to appear in the mapping as well, they will however be marked as deleted in the sorted view.

      Throws:
      IOException
    • getID

      public abstract String getID()
      Returns the identifier of this Sorter.

      This identifier is similar to Object.hashCode() and should be chosen so that two instances of this class that sort documents likewise will have the same identifier. On the contrary, this identifier should be different on different sorters.

    • toString

      public String toString()
      Overrides:
      toString in class Object