Package org.apache.lucene.index
Class Sorter
- java.lang.Object
-
- org.apache.lucene.index.Sorter
-
final class Sorter extends java.lang.Object
Sorts documents of a given index by returning a permutation on the document IDs.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
Sorter.DocComparator
A comparator of doc IDs.(package private) static class
Sorter.DocMap
A permutation of doc IDs.private static class
Sorter.DocValueSorter
(package private) static interface
Sorter.NumericDocValuesSupplier
(package private) static interface
Sorter.SortedDocValuesSupplier
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static Sorter.DocComparator
getDocComparator(int maxDoc, SortField sortField, Sorter.SortedDocValuesSupplier sortedProvider, Sorter.NumericDocValuesSupplier numericProvider)
We cannot use theFieldComparator
API because that API requires that you send it docIDs in order.(package private) static Sorter.DocComparator
getDocComparator(LeafReader reader, SortField sortField)
java.lang.String
getID()
Returns the identifier of thisSorter
.(package private) static NumericDocValues
getOrWrapNumeric(LeafReader reader, SortField sortField)
Wraps aSortedNumericDocValues
as a single-valued view if the field is an instance ofSortedNumericSortField
, returnsNumericDocValues
for the field otherwise.(package private) static SortedDocValues
getOrWrapSorted(LeafReader reader, SortField sortField)
Wraps aSortedSetDocValues
as a single-valued view if the field is an instance ofSortedSetSortField
, returnsSortedDocValues
for the field otherwise.(package private) static SortField.Type
getSortFieldType(SortField sortField)
Returns the native sort type forSortedSetSortField
andSortedNumericSortField
,SortField.getType()
otherwise(package private) static boolean
isConsistent(Sorter.DocMap docMap)
Check consistency of aSorter.DocMap
, useful for assertions.private static Sorter.DocMap
sort(int maxDoc, Sorter.DocComparator comparator)
Computes the old-to-new permutation over the given comparator.(package private) Sorter.DocMap
sort(int maxDoc, Sorter.DocComparator[] comparators)
(package private) Sorter.DocMap
sort(LeafReader reader)
Returns a mapping from the old document ID to its new location in the sorted index.java.lang.String
toString()
-
-
-
Field Detail
-
sort
final Sort sort
-
-
Constructor Detail
-
Sorter
Sorter(Sort sort)
Creates a new Sorter to sort the index withsort
-
-
Method Detail
-
isConsistent
static boolean isConsistent(Sorter.DocMap docMap)
Check consistency of aSorter.DocMap
, useful for assertions.
-
sort
private static Sorter.DocMap sort(int maxDoc, Sorter.DocComparator comparator)
Computes the old-to-new permutation over the given comparator.
-
getSortFieldType
static SortField.Type getSortFieldType(SortField sortField)
Returns the native sort type forSortedSetSortField
andSortedNumericSortField
,SortField.getType()
otherwise
-
getOrWrapNumeric
static NumericDocValues getOrWrapNumeric(LeafReader reader, SortField sortField) throws java.io.IOException
Wraps aSortedNumericDocValues
as a single-valued view if the field is an instance ofSortedNumericSortField
, returnsNumericDocValues
for the field otherwise.- Throws:
java.io.IOException
-
getOrWrapSorted
static SortedDocValues getOrWrapSorted(LeafReader reader, SortField sortField) throws java.io.IOException
Wraps aSortedSetDocValues
as a single-valued view if the field is an instance ofSortedSetSortField
, returnsSortedDocValues
for the field otherwise.- Throws:
java.io.IOException
-
getDocComparator
static Sorter.DocComparator getDocComparator(LeafReader reader, SortField sortField) throws java.io.IOException
- Throws:
java.io.IOException
-
getDocComparator
static Sorter.DocComparator getDocComparator(int maxDoc, SortField sortField, Sorter.SortedDocValuesSupplier sortedProvider, Sorter.NumericDocValuesSupplier numericProvider) throws java.io.IOException
We cannot use theFieldComparator
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 auxiliarysort(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
-
sort
Sorter.DocMap sort(int maxDoc, Sorter.DocComparator[] comparators) throws java.io.IOException
- Throws:
java.io.IOException
-
getID
public java.lang.String getID()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-