Skip to content

Commit

Permalink
Cleanup duplicate FilterScorable in QueryPhaseCollector (elastic#112603)
Browse files Browse the repository at this point in the history
It's in the title, we can dedup the code here.
  • Loading branch information
original-brownbear authored Sep 11, 2024
1 parent c1a2d39 commit fe5d671
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,10 @@ public LeafCollector getLeafCollector(LeafReaderContext context) throws IOExcept
return new FilterLeafCollector(topDocsLeafCollector) {
@Override
public void setScorer(Scorable scorer) throws IOException {
super.setScorer(new FilterScorable(scorer) {
@Override
public void setMinCompetitiveScore(float minScore) {
// Ignore calls to setMinCompetitiveScore. The top docs collector may try to skip low
// scoring hits, but the overall score_mode won't allow it because an aggs collector
// was originally provided which never supports TOP_SCORES is not supported for aggs
}
});
// Ignore calls to setMinCompetitiveScore. The top docs collector may try to skip low
// scoring hits, but the overall score_mode won't allow it because an aggs collector
// was originally provided which never supports TOP_SCORES is not supported for aggs
super.setScorer(wrapToIgnoreMinCompetitiveScore(scorer));
}

@Override
Expand All @@ -208,6 +204,13 @@ public DocIdSetIterator competitiveIterator() throws IOException {
return new CompositeLeafCollector(postFilterBits, topDocsLeafCollector, aggsLeafCollector);
}

private static FilterScorable wrapToIgnoreMinCompetitiveScore(Scorable scorer) {
return new FilterScorable(scorer) {
@Override
public void setMinCompetitiveScore(float minScore) {}
};
}

private class TopDocsLeafCollector implements LeafCollector {
private final Bits postFilterBits;
private final LeafCollector topDocsLeafCollector;
Expand Down Expand Up @@ -262,14 +265,10 @@ public void setScorer(Scorable scorer) throws IOException {
if (cacheScores && topDocsLeafCollector != null && aggsLeafCollector != null) {
scorer = ScoreCachingWrappingScorer.wrap(scorer);
}
scorer = new FilterScorable(scorer) {
@Override
public void setMinCompetitiveScore(float minScore) {
// Ignore calls to setMinCompetitiveScore so that if the top docs collector
// wants to skip low-scoring hits, the aggs collector still sees all hits.
// this is important also for terminate_after in case used when total hits tracking is early terminated.
}
};
// Ignore calls to setMinCompetitiveScore so that if the top docs collector
// wants to skip low-scoring hits, the aggs collector still sees all hits.
// this is important also for terminate_after in case used when total hits tracking is early terminated.
scorer = wrapToIgnoreMinCompetitiveScore(scorer);
if (topDocsLeafCollector != null) {
topDocsLeafCollector.setScorer(scorer);
}
Expand Down

0 comments on commit fe5d671

Please sign in to comment.