mirror of https://github.com/apache/lucene.git
Propagate topLevelScoringClause from QueryProfiler (#13031)
This commit is contained in:
parent
7d35ae4858
commit
7832d3c9fe
|
@ -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
|
||||
---------------------
|
||||
|
||||
|
|
|
@ -94,6 +94,11 @@ class QueryProfilerWeight extends FilterWeight {
|
|||
timer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopLevelScoringClause() throws IOException {
|
||||
subQueryScorerSupplier.setTopLevelScoringClause();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue