Package org.apache.lucene.search
Class HitQueue
- java.lang.Object
-
- org.apache.lucene.util.PriorityQueue<ScoreDoc>
-
- org.apache.lucene.search.HitQueue
-
public final class HitQueue extends PriorityQueue<ScoreDoc>
Expert: Priority queue containing hit docs- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
-
Constructor Summary
Constructors Constructor Description HitQueue(int size, boolean prePopulate)Creates a new instance withsizeelements.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanlessThan(ScoreDoc hitA, ScoreDoc hitB)Determines the ordering of objects in this priority queue.-
Methods inherited from class org.apache.lucene.util.PriorityQueue
add, addAll, clear, getHeapArray, insertWithOverflow, iterator, pop, remove, size, top, updateTop, updateTop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
HitQueue
public HitQueue(int size, boolean prePopulate)Creates a new instance withsizeelements. IfprePopulateis set to true, the queue will pre-populate itself with sentinel objects and set itsPriorityQueue.size()tosize. In that case, you should not rely onPriorityQueue.size()to get the number of actual elements that were added to the queue, but keep track yourself.
NOTE: in caseprePopulateis true, you should pop elements from the queue using the following code example:PriorityQueue<ScoreDoc> pq = new HitQueue(10, true); // pre-populate. ScoreDoc top = pq.top(); // Add/Update one element. top.score = 1.0f; top.doc = 0; top = (ScoreDoc) pq.updateTop(); int totalHits = 1; // Now pop only the elements that were *truly* inserted. // First, pop all the sentinel elements (there are pq.size() - totalHits). for (int i = pq.size() - totalHits; i > 0; i--) pq.pop(); // Now pop the truly added elements. ScoreDoc[] results = new ScoreDoc[totalHits]; for (int i = totalHits - 1; i >= 0; i--) { results[i] = (ScoreDoc) pq.pop(); }NOTE: This class pre-allocate a full array of length
size.- Parameters:
size- the requested size of this queue.prePopulate- specifies whether to pre-populate the queue with sentinel values.
-
-
Method Detail
-
lessThan
protected final boolean lessThan(ScoreDoc hitA, ScoreDoc hitB)
Description copied from class:PriorityQueueDetermines the ordering of objects in this priority queue. Subclasses must define this one method.- Specified by:
lessThanin classPriorityQueue<ScoreDoc>- Returns:
trueiff parameterais less than parameterb.
-
-