From 46ecb739766a1a82b458b417e35f9c0936288e65 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Wed, 2 May 2018 17:20:42 +0200 Subject: [PATCH] LUCENE-8142: Fix AssertingImpactsEnum and add missing javadoc. --- lucene/core/src/java/org/apache/lucene/index/Impacts.java | 3 +++ .../org/apache/lucene/search/DisjunctionMaxScorer.java | 1 + .../org/apache/lucene/search/DisjunctionSumScorer.java | 1 + .../src/java/org/apache/lucene/search/ReqExclScorer.java | 5 +++++ .../src/java/org/apache/lucene/search/ReqOptSumScorer.java | 7 +++++++ .../src/java/org/apache/lucene/search/AssertingScorer.java | 2 +- 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/Impacts.java b/lucene/core/src/java/org/apache/lucene/index/Impacts.java index ce3ece42e5a..f6542b98646 100644 --- a/lucene/core/src/java/org/apache/lucene/index/Impacts.java +++ b/lucene/core/src/java/org/apache/lucene/index/Impacts.java @@ -23,6 +23,9 @@ import java.util.List; */ public abstract class Impacts { + /** Sole constructor. Typically invoked by sub classes. */ + protected Impacts() {} + /** * Return the number of levels on which we have impacts. * The returned value is always greater than 0 and may not always be the diff --git a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java index 3b860687715..6d2f65c04dc 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java @@ -53,6 +53,7 @@ final class DisjunctionMaxScorer extends DisjunctionScorer { float scoreMax = 0; double otherScoreSum = 0; for (Scorer scorer : subScorers) { + scorer.advanceShallow(0); float subScore = scorer.getMaxScore(DocIdSetIterator.NO_MORE_DOCS); if (subScore >= scoreMax) { otherScoreSum += scoreMax; diff --git a/lucene/core/src/java/org/apache/lucene/search/DisjunctionSumScorer.java b/lucene/core/src/java/org/apache/lucene/search/DisjunctionSumScorer.java index fa92fcd0fac..4f45b078117 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionSumScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionSumScorer.java @@ -36,6 +36,7 @@ final class DisjunctionSumScorer extends DisjunctionScorer { super(weight, subScorers, needsScores); double maxScore = 0; for (Scorer scorer : subScorers) { + scorer.advanceShallow(0); maxScore += scorer.getMaxScore(DocIdSetIterator.NO_MORE_DOCS); } // The error of sums depends on the order in which values are summed up. In diff --git a/lucene/core/src/java/org/apache/lucene/search/ReqExclScorer.java b/lucene/core/src/java/org/apache/lucene/search/ReqExclScorer.java index 987293eb047..cee0a452809 100644 --- a/lucene/core/src/java/org/apache/lucene/search/ReqExclScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/ReqExclScorer.java @@ -76,6 +76,11 @@ class ReqExclScorer extends Scorer { return reqScorer.score(); // reqScorer may be null when next() or skipTo() already return false } + @Override + public int advanceShallow(int target) throws IOException { + return reqScorer.advanceShallow(target); + } + @Override public float getMaxScore(int upTo) throws IOException { return reqScorer.getMaxScore(upTo); diff --git a/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java b/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java index 6d93a54560d..418ad99724a 100644 --- a/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java @@ -52,6 +52,7 @@ class ReqOptSumScorer extends Scorer { this.reqScorer = reqScorer; this.optScorer = optScorer; + reqScorer.advanceShallow(0); this.reqMaxScore = reqScorer.getMaxScore(DocIdSetIterator.NO_MORE_DOCS); this.maxScorePropagator = new MaxScoreSumPropagator(Arrays.asList(reqScorer, optScorer)); @@ -209,6 +210,12 @@ class ReqOptSumScorer extends Scorer { return score; } + @Override + public int advanceShallow(int target) throws IOException { + optScorer.advanceShallow(target); + return reqScorer.advanceShallow(target); + } + @Override public float getMaxScore(int upTo) throws IOException { float maxScore = reqScorer.getMaxScore(upTo); diff --git a/lucene/test-framework/src/java/org/apache/lucene/search/AssertingScorer.java b/lucene/test-framework/src/java/org/apache/lucene/search/AssertingScorer.java index 00aee414ddc..952687f27c4 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/search/AssertingScorer.java +++ b/lucene/test-framework/src/java/org/apache/lucene/search/AssertingScorer.java @@ -40,7 +40,7 @@ public class AssertingScorer extends Scorer { IteratorState state = IteratorState.ITERATING; int doc; float minCompetitiveScore = 0; - int lastShallowTarget; + int lastShallowTarget = -1; private AssertingScorer(Random random, Scorer in, ScoreMode scoreMode) { super(in.weight);