gate.creole.annic.apache.lucene.search
Class FieldSortedHitQueue

java.lang.Object
  extended by gate.creole.annic.apache.lucene.util.PriorityQueue
      extended by gate.creole.annic.apache.lucene.search.FieldSortedHitQueue

 class FieldSortedHitQueue
extends PriorityQueue

Expert: A hit queue for sorting by hits by terms in more than one field. Uses FieldCache.DEFAULT for maintaining internal term lookup tables.

Created: Dec 8, 2003 12:56:03 PM

Since:
lucene 1.4
Version:
$Id: FieldSortedHitQueue.java 529 2004-10-05 11:55:26Z niraj $
Author:
Tim Jones (Nacimiento Software)
See Also:
Searchable.search(Query,Filter,int,Sort), FieldCache

Field Summary
protected  ScoreDocComparator[] comparators
          Stores a comparator corresponding to each field being sorted by
(package private) static Map Comparators
          Internal cache of comparators.
protected  SortField[] fields
          Stores the sort criteria being used.
protected  float maxscore
          Stores the maximum score value encountered, for normalizing.
 
Constructor Summary
FieldSortedHitQueue(IndexReader reader, SortField[] fields, int size)
          Creates a hit queue sorted by the given list of fields.
 
Method Summary
(package private) static ScoreDocComparator comparatorAuto(IndexReader reader, String fieldname)
          Returns a comparator for sorting hits according to values in the given field.
(package private) static ScoreDocComparator comparatorFloat(IndexReader reader, String fieldname)
          Returns a comparator for sorting hits according to a field containing floats.
(package private) static ScoreDocComparator comparatorInt(IndexReader reader, String fieldname)
          Returns a comparator for sorting hits according to a field containing integers.
(package private) static ScoreDocComparator comparatorString(IndexReader reader, String fieldname)
          Returns a comparator for sorting hits according to a field containing strings.
(package private) static ScoreDocComparator comparatorStringLocale(IndexReader reader, String fieldname, Locale locale)
          Returns a comparator for sorting hits according to a field containing strings.
(package private)  FieldDoc fillFields(FieldDoc doc)
          Given a FieldDoc object, stores the values used to sort the given document.
(package private) static ScoreDocComparator getCachedComparator(IndexReader reader, String fieldname, int type, Locale locale, SortComparatorSource factory)
           
(package private)  SortField[] getFields()
          Returns the SortFields being used by this hit queue.
protected  boolean lessThan(Object a, Object b)
          Returns whether a is less relevant than b.
(package private) static ScoreDocComparator lookup(IndexReader reader, String field, int type, Object factory)
          Returns a comparator if it is in the cache.
(package private) static Object store(IndexReader reader, String field, int type, Object factory, Object value)
          Stores a comparator into the cache.
 
Methods inherited from class gate.creole.annic.apache.lucene.util.PriorityQueue
adjustTop, clear, initialize, insert, pop, put, size, top
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

comparators

protected ScoreDocComparator[] comparators
Stores a comparator corresponding to each field being sorted by


fields

protected SortField[] fields
Stores the sort criteria being used.


maxscore

protected float maxscore
Stores the maximum score value encountered, for normalizing. we only care about scores greater than 1.0 - if all the scores are less than 1.0, we don't have to normalize.


Comparators

static final Map Comparators
Internal cache of comparators. Similar to FieldCache, only caches comparators instead of term values.

Constructor Detail

FieldSortedHitQueue

FieldSortedHitQueue(IndexReader reader,
                    SortField[] fields,
                    int size)
              throws IOException
Creates a hit queue sorted by the given list of fields.

Parameters:
reader - Index to use.
fields - Field names, in priority order (highest priority first). Cannot be null or empty.
size - The number of hits to retain. Must be greater than zero.
Throws:
IOException
Method Detail

lessThan

protected final boolean lessThan(Object a,
                                 Object b)
Returns whether a is less relevant than b.

Specified by:
lessThan in class PriorityQueue
Parameters:
a - ScoreDoc
b - ScoreDoc
Returns:
true if document a should be sorted after document b.

fillFields

FieldDoc fillFields(FieldDoc doc)
Given a FieldDoc object, stores the values used to sort the given document. These values are not the raw values out of the index, but the internal representation of them. This is so the given search hit can be collated by a MultiSearcher with other search hits.

Parameters:
doc - The FieldDoc to store sort values into.
Returns:
The same FieldDoc passed in.
See Also:
Searchable.search(Query,Filter,int,Sort)

getFields

SortField[] getFields()
Returns the SortFields being used by this hit queue.


lookup

static ScoreDocComparator lookup(IndexReader reader,
                                 String field,
                                 int type,
                                 Object factory)
Returns a comparator if it is in the cache.


store

static Object store(IndexReader reader,
                    String field,
                    int type,
                    Object factory,
                    Object value)
Stores a comparator into the cache.


getCachedComparator

static ScoreDocComparator getCachedComparator(IndexReader reader,
                                              String fieldname,
                                              int type,
                                              Locale locale,
                                              SortComparatorSource factory)
                                       throws IOException
Throws:
IOException

comparatorInt

static ScoreDocComparator comparatorInt(IndexReader reader,
                                        String fieldname)
                                 throws IOException
Returns a comparator for sorting hits according to a field containing integers.

Parameters:
reader - Index to use.
fieldname - Field containg integer values.
Returns:
Comparator for sorting hits.
Throws:
IOException - If an error occurs reading the index.

comparatorFloat

static ScoreDocComparator comparatorFloat(IndexReader reader,
                                          String fieldname)
                                   throws IOException
Returns a comparator for sorting hits according to a field containing floats.

Parameters:
reader - Index to use.
fieldname - Field containg float values.
Returns:
Comparator for sorting hits.
Throws:
IOException - If an error occurs reading the index.

comparatorString

static ScoreDocComparator comparatorString(IndexReader reader,
                                           String fieldname)
                                    throws IOException
Returns a comparator for sorting hits according to a field containing strings.

Parameters:
reader - Index to use.
fieldname - Field containg string values.
Returns:
Comparator for sorting hits.
Throws:
IOException - If an error occurs reading the index.

comparatorStringLocale

static ScoreDocComparator comparatorStringLocale(IndexReader reader,
                                                 String fieldname,
                                                 Locale locale)
                                          throws IOException
Returns a comparator for sorting hits according to a field containing strings.

Parameters:
reader - Index to use.
fieldname - Field containg string values.
Returns:
Comparator for sorting hits.
Throws:
IOException - If an error occurs reading the index.

comparatorAuto

static ScoreDocComparator comparatorAuto(IndexReader reader,
                                         String fieldname)
                                  throws IOException
Returns a comparator for sorting hits according to values in the given field. The terms in the field are looked at to determine whether they contain integers, floats or strings. Once the type is determined, one of the other static methods in this class is called to get the comparator.

Parameters:
reader - Index to use.
fieldname - Field containg values.
Returns:
Comparator for sorting hits.
Throws:
IOException - If an error occurs reading the index.