Fix TermAutomatonScorer.advance corner cases.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1672267 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adrien Grand 2015-04-09 08:52:52 +00:00
parent 5980a4f8f7
commit 651ac092a5
1 changed files with 21 additions and 13 deletions

View File

@ -78,13 +78,7 @@ class TermAutomatonScorer extends Scorer {
for(EnumAndScorer sub : subs) { for(EnumAndScorer sub : subs) {
if (sub != null) { if (sub != null) {
cost += sub.posEnum.cost(); cost += sub.posEnum.cost();
subsOnDoc[numSubsOnDoc++] = sub;
if (sub.posEnum.nextDoc() != NO_MORE_DOCS) {
sub.posLeft = sub.posEnum.freq()-1;
sub.pos = sub.posEnum.nextPosition();
}
docIDQueue.add(sub);
} }
} }
this.cost = cost; this.cost = cost;
@ -137,6 +131,8 @@ class TermAutomatonScorer extends Scorer {
@Override @Override
public int nextDoc() throws IOException { public int nextDoc() throws IOException {
// we only need to advance docs that are positioned since all docs in the
// pq are guaranteed to be beyond the current doc already
for(int i=0;i<numSubsOnDoc;i++) { for(int i=0;i<numSubsOnDoc;i++) {
EnumAndScorer sub = subsOnDoc[i]; EnumAndScorer sub = subsOnDoc[i];
if (sub.posEnum.nextDoc() != NO_MORE_DOCS) { if (sub.posEnum.nextDoc() != NO_MORE_DOCS) {
@ -144,17 +140,27 @@ class TermAutomatonScorer extends Scorer {
sub.pos = sub.posEnum.nextPosition(); sub.pos = sub.posEnum.nextPosition();
} }
} }
pushCurrentDoc();
return doNext(); return doNext();
} }
@Override @Override
public int advance(int target) throws IOException { public int advance(int target) throws IOException {
if (docID == -1) { // Both positioned docs and docs in the pq might be behind target
popCurrentDoc();
if (docID >= target) { // 1. Advance the PQ
return doNext(); if (docIDQueue.size() > 0) {
EnumAndScorer top = docIDQueue.top();
while (top.posEnum.docID() < target) {
if (top.posEnum.advance(target) != NO_MORE_DOCS) {
top.posLeft = top.posEnum.freq()-1;
top.pos = top.posEnum.nextPosition();
}
top = docIDQueue.updateTop();
} }
} }
// 2. Advance subsOnDoc
for(int i=0;i<numSubsOnDoc;i++) { for(int i=0;i<numSubsOnDoc;i++) {
EnumAndScorer sub = subsOnDoc[i]; EnumAndScorer sub = subsOnDoc[i];
if (sub.posEnum.advance(target) != NO_MORE_DOCS) { if (sub.posEnum.advance(target) != NO_MORE_DOCS) {
@ -162,14 +168,15 @@ class TermAutomatonScorer extends Scorer {
sub.pos = sub.posEnum.nextPosition(); sub.pos = sub.posEnum.nextPosition();
} }
} }
pushCurrentDoc();
return doNext(); return doNext();
} }
private int doNext() throws IOException { private int doNext() throws IOException {
assert numSubsOnDoc == 0;
assert docIDQueue.top().posEnum.docID() > docID;
while (true) { while (true) {
//System.out.println(" doNext: cycle"); //System.out.println(" doNext: cycle");
pushCurrentDoc();
popCurrentDoc(); popCurrentDoc();
//System.out.println(" docID=" + docID); //System.out.println(" docID=" + docID);
if (docID == NO_MORE_DOCS) { if (docID == NO_MORE_DOCS) {
@ -186,6 +193,7 @@ class TermAutomatonScorer extends Scorer {
sub.pos = sub.posEnum.nextPosition(); sub.pos = sub.posEnum.nextPosition();
} }
} }
pushCurrentDoc();
} }
} }