Propagate topLevelScoringClause from QueryProfiler (#13031)

This commit is contained in:
Shintaro Murakami 2024-01-29 17:11:42 +09:00 committed by GitHub
parent 7d35ae4858
commit 7832d3c9fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 54 additions and 13 deletions

View File

@ -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
---------------------

View File

@ -94,6 +94,11 @@ class QueryProfilerWeight extends FilterWeight {
timer.stop();
}
}
@Override
public void setTopLevelScoringClause() throws IOException {
subQueryScorerSupplier.setTopLevelScoringClause();
}
};
}

View File

@ -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) {
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 DocIdSetIterator iterator() {
return null;
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 getMaxScore(int upTo) {
return 42f;
public long cost() {
return cost;
}
@Override
public float score() {
return 0;
}
@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());
}
}