Class Sorter


  • final class Sorter
    extends java.lang.Object
    Sorts documents of a given index by returning a permutation on the document IDs.
    • Field Detail

      • sort

        final Sort sort
    • Constructor Detail

      • Sorter

        Sorter​(Sort sort)
        Creates a new Sorter to sort the index with sort
    • Method Detail

      • isConsistent

        static boolean isConsistent​(Sorter.DocMap docMap)
        Check consistency of a Sorter.DocMap, useful for assertions.
      • getDocComparator

        static Sorter.DocComparator getDocComparator​(int maxDoc,
                                                     SortField sortField,
                                                     Sorter.SortedDocValuesSupplier sortedProvider,
                                                     Sorter.NumericDocValuesSupplier numericProvider)
                                              throws java.io.IOException
        We cannot use the FieldComparator API because that API requires that you send it docIDs in order. Note that this API allocates arrays[maxDoc] to hold the native values needed for comparison, but 1) they are transient (only alive while sorting this one segment), and 2) in the typical index sorting case, they are only used to sort newly flushed segments, which will be smaller than merged segments.
        Throws:
        java.io.IOException
      • sort

        Sorter.DocMap sort​(LeafReader reader)
                    throws java.io.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:
        java.io.IOException
      • getID

        public java.lang.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 sorts.

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object