21 using Lucene.Net.Support;
23 using Scorer = Lucene.Net.Search.Scorer;
25 namespace Lucene.Net.Util
35 private HeapedScorerDoc[] heap;
39 private class HeapedScorerDoc
43 this.enclosingInstance = enclosingInstance;
50 return enclosingInstance;
57 internal HeapedScorerDoc(
ScorerDocQueue enclosingInstance,
Scorer s):
this(enclosingInstance, s, s.DocID())
63 InitBlock(enclosingInstance);
68 internal virtual void Adjust()
74 private HeapedScorerDoc topHSD;
81 int heapSize = maxSize + 1;
82 heap =
new HeapedScorerDoc[heapSize];
83 this.maxSize = maxSize;
94 heap[size] =
new HeapedScorerDoc(
this, scorer);
105 public virtual bool Insert(
Scorer scorer)
114 int docNr = scorer.DocID();
115 if ((size > 0) && (!(docNr < topHSD.doc)))
118 heap[1] =
new HeapedScorerDoc(
this, scorer, docNr);
135 return topHSD.scorer;
148 public float TopScore()
151 return topHSD.scorer.Score();
154 public bool TopNextAndAdjustElsePop()
156 return CheckAdjustElsePop(topHSD.scorer.NextDoc() !=
DocIdSetIterator.NO_MORE_DOCS);
159 public bool TopSkipToAndAdjustElsePop(
int target)
161 return CheckAdjustElsePop(topHSD.scorer.Advance(target) !=
DocIdSetIterator.NO_MORE_DOCS);
164 private bool CheckAdjustElsePop(
bool cond)
169 topHSD.doc = topHSD.scorer.DocID();
174 heap[1] = heap[size];
189 Scorer result = topHSD.scorer;
197 private void PopNoResult()
199 heap[1] = heap[size];
212 public void AdjustTop()
228 for (
int i = 0; i <= size; i++)
235 private void UpHeap()
238 HeapedScorerDoc node = heap[i];
240 while ((j > 0) && (node.doc < heap[j].doc))
250 private void DownHeap()
253 HeapedScorerDoc node = heap[i];
256 if ((k <= size) && (heap[k].doc < heap[j].doc))
260 while ((j <= size) && (heap[j].doc < node.doc))
266 if (k <= size && (heap[k].doc < heap[j].doc))