20 namespace Lucene.Net.Search
32 private Scorer[] subScorers;
33 private int numScorers;
35 private float tieBreakerMultiplier;
36 private int doc = - 1;
55 this.tieBreakerMultiplier = tieBreakerMultiplier;
59 this.subScorers = subScorers;
60 this.numScorers = numScorers;
65 public override int NextDoc()
68 return doc = NO_MORE_DOCS;
69 while (subScorers[0].DocID() == doc)
71 if (subScorers[0].NextDoc() != NO_MORE_DOCS)
80 return doc = NO_MORE_DOCS;
85 return doc = subScorers[0].DocID();
88 public override int DocID()
96 public override float Score()
98 int doc = subScorers[0].DocID();
99 float[] sum =
new float[]{subScorers[0].Score()}, max =
new float[]{sum[0]};
100 int size = numScorers;
101 ScoreAll(1, size, doc, sum, max);
102 ScoreAll(2, size, doc, sum, max);
103 return max[0] + (sum[0] - max[0]) * tieBreakerMultiplier;
107 private void ScoreAll(
int root,
int size,
int doc,
float[] sum,
float[] max)
109 if (root < size && subScorers[root].DocID() == doc)
111 float sub = subScorers[root].Score();
113 max[0] = System.Math.Max(max[0], sub);
114 ScoreAll((root << 1) + 1, size, doc, sum, max);
115 ScoreAll((root << 1) + 2, size, doc, sum, max);
119 public override int Advance(
int target)
122 return doc = NO_MORE_DOCS;
123 while (subScorers[0].DocID() < target)
125 if (subScorers[0].Advance(target) != NO_MORE_DOCS)
134 return doc = NO_MORE_DOCS;
138 return doc = subScorers[0].DocID();
142 private void Heapify()
144 for (
int i = (numScorers >> 1) - 1; i >= 0; i--)
153 private void HeapAdjust(
int root)
155 Scorer scorer = subScorers[root];
156 int doc = scorer.DocID();
158 while (i <= (numScorers >> 1) - 1)
160 int lchild = (i << 1) + 1;
161 Scorer lscorer = subScorers[lchild];
162 int ldoc = lscorer.DocID();
163 int rdoc = System.Int32.MaxValue, rchild = (i << 1) + 2;
165 if (rchild < numScorers)
167 rscorer = subScorers[rchild];
168 rdoc = rscorer.DocID();
174 subScorers[i] = rscorer;
175 subScorers[rchild] = scorer;
180 subScorers[i] = lscorer;
181 subScorers[lchild] = scorer;
187 subScorers[i] = rscorer;
188 subScorers[rchild] = scorer;
199 private void HeapRemoveRoot()
203 subScorers[0] = null;
208 subScorers[0] = subScorers[numScorers - 1];
209 subScorers[numScorers - 1] = null;