Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.lucene.search
Class SortComparator

    java.lang.Object
      org.apache.lucene.search.SortComparator

All Implemented Interfaces:
  Serializable, SortComparatorSource

public abstract class SortComparator
extends Object
implements SortComparatorSource

Abstract base class for sorting hits returned by a Query.

This class should only be used if the other SortField types (SCORE, DOC, STRING, INT, FLOAT) do not provide an adequate sorting. It maintains an internal cache of values which could be quite large. The cache is an array of Comparable, one for each document in the index. There is a distinct Comparable for each unique term in the field - if some documents have the same term in the field, the cache array will have entries which reference the same Comparable.

Created: Apr 21, 2004 5:08:38 PM

Since:
  1.4
Version:
  $Id: SortComparator.java,v 1.2.2.1 2004/09/30 19:20:16 dnaber Exp $
Author:
  Tim Jones
See Also:
  Serialized Form

Constructor Summary
`SortComparator()`

Method Summary
`protected abstract Comparable` | `getComparable(String termtext)` Returns an object which, when sorted according to natural order, will order the Term values in the correct order.
`ScoreDocComparator` | `newComparator(IndexReader reader, String fieldname)` Creates a comparator for the field in the given index.

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

Constructor Detail

### SortComparator

    public SortComparator()

Method Detail

### newComparator

    public ScoreDocComparator newComparator(IndexReader reader,
                                            String fieldname)
                                     throws IOException

  Description copied from interface: `SortComparatorSource`
  Creates a comparator for the field in the given index.

  Specified by:
    `newComparator` in interface `SortComparatorSource`
  Parameters:
    `reader` - Index to create comparator for.
    `fieldname` - Field to create comparator for.
  Returns:
    Comparator of ScoreDoc objects.
  Throws:
    `IOException` - If an error occurs reading the index.

### getComparable

    protected abstract Comparable getComparable(String termtext)

  Returns an object which, when sorted according to natural order, will order the Term values in the correct order.

  For example, if the Terms contained integer values, this method would return `new Integer(termtext)`. Note that this might not always be the most efficient implementation - for this particular example, a better implementation might be to make a ScoreDocLookupComparator that uses an internal lookup table of int.

  Parameters:
    `termtext` - The textual value of the term.
  Returns:
    An object representing `termtext` that sorts according to the natural order of `termtext`.
  See Also:
    `Comparable`, `ScoreDocComparator`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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