Methods Summary |
---|
public void | add(org.apache.lucene.search.Scorer scorer)Add the scorer for a subquery
if (scorer.next()) { // Initialize and retain only if it produces docs
subScorers.add(scorer);
more = true;
}
|
public int | doc()Determine the current document number. Initially invalid, until {@link #next()} is called the first time.
return ((Scorer) subScorers.get(0)).doc();
|
public org.apache.lucene.search.Explanation | explain(int doc)Explain a score that we computed. UNSUPPORTED -- see explanation capability in DisjunctionMaxQuery.
throw new UnsupportedOperationException();
|
private void | heapAdjust(int root)
Scorer scorer=(Scorer)subScorers.get(root);
int doc=scorer.doc();
int i=root, size=subScorers.size();
while (i<=(size>>1)-1) {
int lchild=(i<<1)+1;
Scorer lscorer=(Scorer)subScorers.get(lchild);
int ldoc=lscorer.doc();
int rdoc=Integer.MAX_VALUE, rchild=(i<<1)+2;
Scorer rscorer=null;
if (rchild<size) {
rscorer=(Scorer)subScorers.get(rchild);
rdoc=rscorer.doc();
}
if (ldoc<doc) {
if (rdoc<ldoc) {
subScorers.set(i, rscorer);
subScorers.set(rchild, scorer);
i=rchild;
} else {
subScorers.set(i, lscorer);
subScorers.set(lchild, scorer);
i=lchild;
}
} else if (rdoc<doc) {
subScorers.set(i, rscorer);
subScorers.set(rchild, scorer);
i=rchild;
} else return;
}
|
private void | heapRemoveRoot()
int size=subScorers.size();
if (size==1)
subScorers.remove(0);
else {
subScorers.set(0, subScorers.get(size-1));
subScorers.remove(size-1);
heapAdjust(0);
}
|
private void | heapify()
int size = subScorers.size();
for (int i=(size>>1)-1; i>=0; i--)
heapAdjust(i);
|
public boolean | next()Generate the next document matching our associated DisjunctionMaxQuery.
if (!more) return false;
if (firstTime) {
heapify();
firstTime = false;
return true; // more would have been false if no subScorers had any docs
}
// Increment all generators that generated the last doc and adjust the heap.
int lastdoc = ((Scorer) subScorers.get(0)).doc();
do {
if (((Scorer) subScorers.get(0)).next())
heapAdjust(0);
else {
heapRemoveRoot();
if (subScorers.isEmpty()) return (more = false);
}
} while ( ((Scorer) subScorers.get(0)).doc()==lastdoc );
return true;
|
public float | score()Determine the current document score. Initially invalid, until {@link #next()} is called the first time.
int doc = ((Scorer) subScorers.get(0)).doc();
float[] sum = {((Scorer) subScorers.get(0)).score()}, max = {sum[0]};
int size = subScorers.size();
scoreAll(1, size, doc, sum, max);
scoreAll(2, size, doc, sum, max);
return max[0] + (sum[0] - max[0])*tieBreakerMultiplier;
|
private void | scoreAll(int root, int size, int doc, float[] sum, float[] max)
if (root<size && ((Scorer) subScorers.get(root)).doc() == doc) {
float sub = ((Scorer) subScorers.get(root)).score();
sum[0] += sub;
max[0] = Math.max(max[0], sub);
scoreAll((root<<1)+1, size, doc, sum, max);
scoreAll((root<<1)+2, size, doc, sum, max);
}
|
public boolean | skipTo(int target)Advance to the first document beyond the current whose number is greater than or equal to target.
if (firstTime) {
if (!more) return false;
heapify();
firstTime = false;
}
while (subScorers.size()>0 && ((Scorer)subScorers.get(0)).doc()<target) {
if (((Scorer)subScorers.get(0)).skipTo(target))
heapAdjust(0);
else
heapRemoveRoot();
}
if ((subScorers.size()==0))
return (more = false);
return true;
|