mirror of https://github.com/apache/lucene.git
Support getMaxScore of ConjunctionScorer for non top level scoring clause (#13043)
This commit is contained in:
parent
21e545501e
commit
141413633f
|
@ -202,6 +202,8 @@ Improvements
|
|||
|
||||
* GITHUB#12999: Use Automaton for SurroundQuery prefix/pattern matching (Michael Gibney)
|
||||
|
||||
* GITHUB#13043: Support getMaxScore of ConjunctionScorer for non top level scoring clause. (Shintaro Murakami)
|
||||
|
||||
Optimizations
|
||||
---------------------
|
||||
|
||||
|
|
|
@ -65,15 +65,13 @@ class ConjunctionScorer extends Scorer {
|
|||
|
||||
@Override
|
||||
public float getMaxScore(int upTo) throws IOException {
|
||||
// This scorer is only used for TOP_SCORES when there is at most one scoring clause
|
||||
switch (scorers.length) {
|
||||
case 0:
|
||||
return 0;
|
||||
case 1:
|
||||
return scorers[0].getMaxScore(upTo);
|
||||
default:
|
||||
return Float.POSITIVE_INFINITY;
|
||||
double maxScore = 0;
|
||||
for (Scorer s : scorers) {
|
||||
if (s.docID() <= upTo) {
|
||||
maxScore += s.getMaxScore(upTo);
|
||||
}
|
||||
}
|
||||
return (float) maxScore;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,6 +79,9 @@ class ConjunctionScorer extends Scorer {
|
|||
if (scorers.length == 1) {
|
||||
return scorers[0].advanceShallow(target);
|
||||
}
|
||||
for (Scorer scorer : scorers) {
|
||||
scorer.advanceShallow(target);
|
||||
}
|
||||
return super.advanceShallow(target);
|
||||
}
|
||||
|
||||
|
|
|
@ -521,4 +521,20 @@ public class TestBoolean2ScorerSupplier extends LuceneTestCase {
|
|||
assertTrue(clause1.topLevelScoringClause);
|
||||
assertFalse(clause2.topLevelScoringClause);
|
||||
}
|
||||
|
||||
public void testMaxScoreNonTopLevelScoringClause() throws Exception {
|
||||
Map<Occur, Collection<ScorerSupplier>> subs = new EnumMap<>(Occur.class);
|
||||
for (Occur occur : Occur.values()) {
|
||||
subs.put(occur, new ArrayList<>());
|
||||
}
|
||||
|
||||
FakeScorerSupplier clause1 = new FakeScorerSupplier(10, 10);
|
||||
subs.get(Occur.MUST).add(clause1);
|
||||
FakeScorerSupplier clause2 = new FakeScorerSupplier(10, 10);
|
||||
subs.get(Occur.MUST).add(clause2);
|
||||
|
||||
Scorer scorer =
|
||||
new Boolean2ScorerSupplier(new FakeWeight(), subs, ScoreMode.TOP_SCORES, 0).get(10);
|
||||
assertEquals(2.0, scorer.getMaxScore(DocIdSetIterator.NO_MORE_DOCS), 0.0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue