Apache Lucene open-source search software
Propagate topLevelScoringClause from QueryProfiler (#13031)
Shintaro Murakami7832d3c9fe50
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex fa460204306..582ecd966ab 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -240,6 +240,8 @@ Bug Fixes* GITHUB#12287: Fix a bug in ShapeTestUtil. (Heemin Kim)+* GITHUB#13031: ScorerSupplier created by QueryProfilerWeight will propagate topLevelScoringClause to the sub ScorerSupplier. (Shintaro Murakami)+Build---------------------diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerWeight.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerWeight.javaindex 8caaac02139..47c16c4dc22 100644--- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerWeight.java+++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerWeight.java@@ -94,6 +94,11 @@ class QueryProfilerWeight extends FilterWeight {timer.stop();}}++ @Override+ public void setTopLevelScoringClause() throws IOException {+ subQueryScorerSupplier.setTopLevelScoringClause();+ }};}diff --git a/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestQueryProfilerWeight.java b/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestQueryProfilerWeight.javaindex 41b4007155b..7c9e6736cc5 100644--- a/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestQueryProfilerWeight.java+++ b/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestQueryProfilerWeight.java@@ -29,6 +29,7 @@ import org.apache.lucene.search.Matches;import org.apache.lucene.search.MatchesIterator;import org.apache.lucene.search.Query;import org.apache.lucene.search.Scorer;+import org.apache.lucene.search.ScorerSupplier;import org.apache.lucene.search.Weight;import org.apache.lucene.tests.util.LuceneTestCase;@@ -45,26 +46,49 @@ public class TestQueryProfilerWeight extends LuceneTestCase {}@Override- public Scorer scorer(LeafReaderContext context) {- return new Scorer(this) {- @Override- public DocIdSetIterator iterator() {- return null;- }+ public Scorer scorer(LeafReaderContext context) throws IOException {+ return scorerSupplier(context).get(Long.MAX_VALUE);+ }++ @Override+ public ScorerSupplier scorerSupplier(LeafReaderContext context) {+ Weight weight = this;+ return new ScorerSupplier() {+ private long cost = 0;@Override- public float getMaxScore(int upTo) {- return 42f;+ public Scorer get(long leadCost) {+ return new Scorer(weight) {+ @Override+ public DocIdSetIterator iterator() {+ return null;+ }++ @Override+ public float getMaxScore(int upTo) {+ return 42f;+ }++ @Override+ public float score() {+ return 0;+ }++ @Override+ public int docID() {+ return 0;+ }+ };}@Override- public float score() {- return 0;+ public long cost() {+ return cost;}@Override- public int docID() {- return 0;+ public void setTopLevelScoringClause() {+ cost = 42;}};}@@ -153,4 +177,14 @@ public class TestQueryProfilerWeight extends LuceneTestCase {QueryProfilerWeight profileWeight = new QueryProfilerWeight(fakeWeight, profile);assertEquals(42f, profileWeight.scorer(null).getMaxScore(DocIdSetIterator.NO_MORE_DOCS), 0f);}++ public void testPropagateTopLevelScoringClause() throws IOException {+ Query query = new MatchAllDocsQuery();+ Weight fakeWeight = new FakeWeight(query);+ QueryProfilerBreakdown profile = new QueryProfilerBreakdown();+ QueryProfilerWeight profileWeight = new QueryProfilerWeight(fakeWeight, profile);+ ScorerSupplier scorerSupplier = profileWeight.scorerSupplier(null);+ scorerSupplier.setTopLevelScoringClause();+ assertEquals(42, scorerSupplier.cost());+ }}