Skip to content

Commit

Permalink
call createWeight on the query rather the searcher in order to avoid …
Browse files Browse the repository at this point in the history
…query caching
  • Loading branch information
jimczi committed Oct 29, 2019
1 parent 9ef8948 commit e88b7fd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,6 @@ public class ContextIndexSearcher extends IndexSearcher {
*/
private static int CHECK_CANCELLED_SCORER_INTERVAL = 1 << 11;

/**
* A policy to bypass the cache entirely
*/
private static final QueryCachingPolicy NEVER_CACHE_POLICY = new QueryCachingPolicy() {
@Override
public void onUse(Query query) {}

@Override
public boolean shouldCache(Query query) {
return false;
}
};

private AggregatedDfs aggregatedDfs;
private QueryProfiler profiler;
private Runnable checkCancelled;
Expand All @@ -92,10 +79,6 @@ public ContextIndexSearcher(IndexReader reader, Similarity similarity, QueryCach
}

public void setProfiler(QueryProfiler profiler) {
if (profiler != null) {
// disable query caching on profiled query
setQueryCachingPolicy(NEVER_CACHE_POLICY);
}
this.profiler = profiler;
}

Expand Down Expand Up @@ -137,7 +120,7 @@ public Weight createWeight(Query query, ScoreMode scoreMode, float boost) throws
timer.start();
final Weight weight;
try {
weight = super.createWeight(query, scoreMode, boost);
weight = query.createWeight(this, scoreMode, boost);
} finally {
timer.stop();
profiler.pollLastElement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public void testProfileDisableCache() throws Exception {
)
.get()
);
indexRandom(true, client.prepareIndex("index", "_doc").setSource("k", "hello"));
indexRandom(true, client.prepareIndex("index").setSource("k", "hello"));
ensureSearchable("index");

int expectedHits = 0;
Expand Down

0 comments on commit e88b7fd

Please sign in to comment.