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#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
|
Optimizations
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
|
|
@ -65,15 +65,13 @@ class ConjunctionScorer extends Scorer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getMaxScore(int upTo) throws IOException {
|
public float getMaxScore(int upTo) throws IOException {
|
||||||
// This scorer is only used for TOP_SCORES when there is at most one scoring clause
|
double maxScore = 0;
|
||||||
switch (scorers.length) {
|
for (Scorer s : scorers) {
|
||||||
case 0:
|
if (s.docID() <= upTo) {
|
||||||
return 0;
|
maxScore += s.getMaxScore(upTo);
|
||||||
case 1:
|
}
|
||||||
return scorers[0].getMaxScore(upTo);
|
|
||||||
default:
|
|
||||||
return Float.POSITIVE_INFINITY;
|
|
||||||
}
|
}
|
||||||
|
return (float) maxScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -81,6 +79,9 @@ class ConjunctionScorer extends Scorer {
|
||||||
if (scorers.length == 1) {
|
if (scorers.length == 1) {
|
||||||
return scorers[0].advanceShallow(target);
|
return scorers[0].advanceShallow(target);
|
||||||
}
|
}
|
||||||
|
for (Scorer scorer : scorers) {
|
||||||
|
scorer.advanceShallow(target);
|
||||||
|
}
|
||||||
return super.advanceShallow(target);
|
return super.advanceShallow(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -521,4 +521,20 @@ public class TestBoolean2ScorerSupplier extends LuceneTestCase {
|
||||||
assertTrue(clause1.topLevelScoringClause);
|
assertTrue(clause1.topLevelScoringClause);
|
||||||
assertFalse(clause2.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