## org.apache.lucene.index.sorter
Class Sorter

    java.lang.Object
      org.apache.lucene.index.sorter.Sorter

Direct Known Subclasses:
  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.

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

Nested Class Summary
`static class` `Sorter.DocComparator` A comparator of doc IDs.
`static class` `Sorter.DocMap` A permutation of doc IDs.

Field Summary
`static Sorter` `REVERSE_DOCS` Sorts documents in reverse order.

Constructor Summary
`Sorter()`

Method Summary
`abstract String` `getID()` Returns the identifier of this `Sorter`.
`abstract Sorter.DocMap` `sort(AtomicReader reader)` Returns a mapping from the old document ID to its new location in the sorted index.
`protected static Sorter.DocMap` `sort(int maxDoc, Sorter.DocComparator comparator)` Computes the old-to-new permutation over the given comparator.
`String` `toString()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### 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 Detail

### Sorter

    public Sorter()

Method Detail

### sort

    protected static Sorter.DocMap sort(int maxDoc,
                                        Sorter.DocComparator comparator)

  Computes the old-to-new permutation over the given comparator.

### 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`

Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.