mirror of https://github.com/apache/lucene.git
LUCENE-6748: Never cache MatchAllDocsQuery and other cheap queries.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1696900 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ef09fe95d5
commit
2b05cda72c
|
@ -81,6 +81,9 @@ Bug Fixes
|
|||
|
||||
* LUCENE-6745: RAMInputStream.clone was not thread safe (Mike McCandless)
|
||||
|
||||
* LUCENE-6748: UsageTrackingQueryCachingPolicy no longer caches trivial queries
|
||||
like MatchAllDocsQuery. (Adrien Grand)
|
||||
|
||||
Other
|
||||
|
||||
* LUCENE-6174: Improve "ant eclipse" to select right JRE for building.
|
||||
|
|
|
@ -123,6 +123,24 @@ public final class UsageTrackingQueryCachingPolicy implements QueryCachingPolicy
|
|||
|
||||
@Override
|
||||
public boolean shouldCache(Query query, LeafReaderContext context) throws IOException {
|
||||
if (query instanceof MatchAllDocsQuery
|
||||
// MatchNoDocsQuery currently rewrites to a BooleanQuery,
|
||||
// but who knows, it might get its own Weight one day
|
||||
|| query instanceof MatchNoDocsQuery) {
|
||||
return false;
|
||||
}
|
||||
if (query instanceof BooleanQuery) {
|
||||
BooleanQuery bq = (BooleanQuery) query;
|
||||
if (bq.clauses().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (query instanceof DisjunctionMaxQuery) {
|
||||
DisjunctionMaxQuery dmq = (DisjunctionMaxQuery) query;
|
||||
if (dmq.getDisjuncts().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (segmentPolicy.shouldCache(query, context) == false) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ package org.apache.lucene.search;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.index.MultiReader;
|
||||
import org.apache.lucene.index.SlowCompositeReaderWrapper;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
|
||||
|
@ -41,4 +43,13 @@ public class TestUsageTrackingFilterCachingPolicy extends LuceneTestCase {
|
|||
assertEquals(2, policy.frequency(q3));
|
||||
}
|
||||
|
||||
public void testNeverCacheMatchAll() throws Exception {
|
||||
Query q = new MatchAllDocsQuery();
|
||||
UsageTrackingQueryCachingPolicy policy = new UsageTrackingQueryCachingPolicy();
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
policy.onUse(q);
|
||||
}
|
||||
assertFalse(policy.shouldCache(q, SlowCompositeReaderWrapper.wrap(new MultiReader()).getContext()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue