Skip specialized bulk scorer if two-phase

This commit is contained in:
Adrien Grand 2024-12-03 17:45:22 +01:00
parent 9b314aa155
commit 4ec12bb6ab
1 changed files with 13 additions and 6 deletions

View File

@ -305,7 +305,7 @@ final class BooleanScorerSupplier extends ScorerSupplier {
|| subs.get(Occur.FILTER).isEmpty() || subs.get(Occur.FILTER).isEmpty()
|| scoreMode != ScoreMode.TOP_SCORES || scoreMode != ScoreMode.TOP_SCORES
|| subs.get(Occur.SHOULD).size() <= 1 || subs.get(Occur.SHOULD).size() <= 1
|| minShouldMatch > 1) { || minShouldMatch != 1) {
return null; return null;
} }
@ -333,13 +333,20 @@ final class BooleanScorerSupplier extends ScorerSupplier {
for (ScorerSupplier ss : subs.get(Occur.FILTER)) { for (ScorerSupplier ss : subs.get(Occur.FILTER)) {
filters.add(ss.get(cost)); filters.add(ss.get(cost));
} }
Scorer filterScorer;
if (filters.size() == 1) { if (filters.stream().map(Scorer::twoPhaseIterator).anyMatch(Objects::nonNull)) {
filterScorer = filters.iterator().next(); Scorer scoring = new WANDScorer(optionalScorers, minShouldMatch, scoreMode, cost);
filters.add(scoring);
return new DefaultBulkScorer(new ConjunctionScorer(filters, Collections.singleton(scoring)));
} else { } else {
filterScorer = new ConjunctionScorer(filters, Collections.emptySet()); Scorer filterScorer;
if (filters.size() == 1) {
filterScorer = filters.iterator().next();
} else {
filterScorer = new ConjunctionScorer(filters, Collections.emptySet());
}
return new MaxScoreBulkScorer(maxDoc, optionalScorers, filterScorer);
} }
return new MaxScoreBulkScorer(maxDoc, optionalScorers, filterScorer);
} }
// Return a BulkScorer for the required clauses only // Return a BulkScorer for the required clauses only