Skip to content

Commit

Permalink
Fix IndexSearcher wrappers interaction with AssertingIndexSearcher
Browse files Browse the repository at this point in the history
This commit ensures that we delegate the creation of the query weight to the AssertingIndexSearcher
when possible (if the query does not need to access distributed frequency statistics). This fixes test failures
that uses a ContextIndexSearcher wrapped with an AssertingIndexSearcher.

Relates elastic#39071
  • Loading branch information
jimczi committed Mar 15, 2019
1 parent 8579235 commit 84bab4c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ public XIndexSearcher(IndexSearcher in) {
public void search(List<LeafReaderContext> leaves, Weight weight, Collector collector) throws IOException {
in.search(leaves, weight, collector);
}

@Override
public Weight createWeight(Query query, ScoreMode scoreMode, float boost) throws IOException {
return in.createWeight(query, scoreMode, boost);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,19 @@ public Weight createWeight(Query query, ScoreMode scoreMode, float boost) throws
timer.start();
final Weight weight;
try {
weight = super.createWeight(query, scoreMode, boost);
weight = aggregatedDfs == null ? in.createWeight(query, scoreMode, boost) :
// needs to be 'super', not 'in' in order to use aggregated DFS
super.createWeight(query, scoreMode, boost);
} finally {
timer.stop();
profiler.pollLastElement();
}
return new ProfileWeight(query, weight, profile);
} else {
// needs to be 'super', not 'in' in order to use aggregated DFS
return super.createWeight(query, scoreMode, boost);
return aggregatedDfs == null ? in.createWeight(query, scoreMode, boost) :
// needs to be 'super', not 'in' in order to use aggregated DFS
super.createWeight(query, scoreMode, boost);

}
}

Expand Down Expand Up @@ -179,11 +183,9 @@ public BulkScorer bulkScorer(LeafReaderContext context) throws IOException {

@Override
public Explanation explain(Query query, int doc) throws IOException {
if (aggregatedDfs != null) {
return aggregatedDfs == null ? in.explain(query, doc) :
// dfs data is needed to explain the score
return super.explain(createWeight(rewrite(query), ScoreMode.COMPLETE, 1f), doc);
}
return in.explain(query, doc);
super.explain(createWeight(rewrite(query), ScoreMode.COMPLETE, 1f), doc);
}

@Override
Expand Down

0 comments on commit 84bab4c

Please sign in to comment.