LUCENE-9287: UsageTrackingQueryCachingPolicy no longer caches DocValuesFieldExistsQuery (#1374)

This commit is contained in:
Ignacio Vera 2020-03-24 15:26:56 +01:00 committed by GitHub
parent 20abf3e478
commit 674aba6a85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -127,6 +127,8 @@ Optimizations
* LUCENE-8103: DoubleValuesSource and QueryValueSource now use a TwoPhaseIterator if one is provided by the Query.
(Michele Palmia, David Smiley)
* LUCENE-9287: UsageTrackingQueryCachingPolicy no longer caches DocValuesFieldExistsQuery. (Ignacio Vera)
Bug Fixes
---------------------
* LUCENE-9259: Fix wrong NGramFilterFactory argument name for preserveOriginal option (Paul Pazderski)

View File

@ -60,6 +60,11 @@ public class UsageTrackingQueryCachingPolicy implements QueryCachingPolicy {
return true;
}
if (query instanceof DocValuesFieldExistsQuery) {
// We do not bother caching DocValuesFieldExistsQuery queries since they are already plenty fast.
return true;
}
if (query instanceof MatchAllDocsQuery) {
// MatchAllDocsQuery has an iterator that is faster than what a bit set could do.
return true;

View File

@ -54,6 +54,15 @@ public class TestUsageTrackingFilterCachingPolicy extends LuceneTestCase {
assertFalse(policy.shouldCache(q));
}
public void testNeverCacheDocValuesFieldExistsFilter() throws IOException {
Query q = new DocValuesFieldExistsQuery("foo");
UsageTrackingQueryCachingPolicy policy = new UsageTrackingQueryCachingPolicy();
for (int i = 0; i < 1000; ++i) {
policy.onUse(q);
}
assertFalse(policy.shouldCache(q));
}
public void testBooleanQueries() throws IOException {
Directory dir = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random(), dir);