From 651ac092a55bd696c242a9c8850b78c5af02d061 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 9 Apr 2015 08:52:52 +0000 Subject: [PATCH] Fix TermAutomatonScorer.advance corner cases. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1672267 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/search/TermAutomatonScorer.java | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonScorer.java b/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonScorer.java index de261c467a2..b8f6cb2770d 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonScorer.java +++ b/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonScorer.java @@ -78,13 +78,7 @@ class TermAutomatonScorer extends Scorer { for(EnumAndScorer sub : subs) { if (sub != null) { cost += sub.posEnum.cost(); - - if (sub.posEnum.nextDoc() != NO_MORE_DOCS) { - sub.posLeft = sub.posEnum.freq()-1; - sub.pos = sub.posEnum.nextPosition(); - } - - docIDQueue.add(sub); + subsOnDoc[numSubsOnDoc++] = sub; } } this.cost = cost; @@ -137,6 +131,8 @@ class TermAutomatonScorer extends Scorer { @Override 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= target) { - return doNext(); + // Both positioned docs and docs in the pq might be behind target + + // 1. Advance the PQ + 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 docID; while (true) { //System.out.println(" doNext: cycle"); - pushCurrentDoc(); popCurrentDoc(); //System.out.println(" docID=" + docID); if (docID == NO_MORE_DOCS) { @@ -186,6 +193,7 @@ class TermAutomatonScorer extends Scorer { sub.pos = sub.posEnum.nextPosition(); } } + pushCurrentDoc(); } }