public static final class

FieldComparator.RelevanceComparator

extends FieldComparator
java.lang.Object
   ↳ org.apache.lucene.search.FieldComparator
     ↳ org.apache.lucene.search.FieldComparator.RelevanceComparator

Class Overview

Sorts by descending relevance. NOTE: if you are sorting only by descending relevance and then secondarily by ascending docID, performance is faster using TopScoreDocCollector directly (which search(Query, int) uses when no Sort is specified).

Summary

Public Methods
int compare(int slot1, int slot2)
Compare hit at slot1 with hit at slot2.
int compareBottom(int doc)
Compare the bottom of the queue with doc.
void copy(int slot, int doc)
This method is called when a new hit is competitive.
void setBottom(int bottom)
Set the bottom slot, ie the "weakest" (sorted last) entry in the queue.
void setNextReader(IndexReader reader, int docBase)
Set a new Reader.
void setScorer(Scorer scorer)
Sets the Scorer to use in case a document's score is needed.
Comparable value(int slot)
Return the actual value in the slot.
[Expand]
Inherited Methods
From class org.apache.lucene.search.FieldComparator
From class java.lang.Object

Public Methods

public int compare (int slot1, int slot2)

Compare hit at slot1 with hit at slot2.

Parameters
slot1 first slot to compare
slot2 second slot to compare
Returns
  • any N < 0 if slot2's value is sorted after slot1, any N > 0 if the slot2's value is sorted before slot1 and 0 if they are equal

public int compareBottom (int doc)

Compare the bottom of the queue with doc. This will only invoked after setBottom has been called. This should return the same result as compare(int, int)} as if bottom were slot1 and the new document were slot 2.

For a search that hits many results, this method will be the hotspot (invoked by far the most frequently).

Parameters
doc that was hit
Returns
  • any N < 0 if the doc's value is sorted after the bottom entry (not competitive), any N > 0 if the doc's value is sorted before the bottom entry and 0 if they are equal.
Throws
IOException

public void copy (int slot, int doc)

This method is called when a new hit is competitive. You should copy any state associated with this document that will be required for future comparisons, into the specified slot.

Parameters
slot which slot to copy the hit to
doc docID relative to current reader
Throws
IOException

public void setBottom (int bottom)

Set the bottom slot, ie the "weakest" (sorted last) entry in the queue. When compareBottom(int) is called, you should compare against this slot. This will always be called before compareBottom(int).

Parameters
bottom the currently weakest (sorted last) slot in the queue

public void setNextReader (IndexReader reader, int docBase)

Set a new Reader. All doc correspond to the current Reader.

Parameters
reader current reader
docBase docBase of this reader

public void setScorer (Scorer scorer)

Sets the Scorer to use in case a document's score is needed.

Parameters
scorer Scorer instance that you should use to obtain the current hit's score, if necessary.

public Comparable value (int slot)

Return the actual value in the slot.

Parameters
slot the value
Returns
  • value in this slot upgraded to Comparable