Package org.apache.lucene.search
Class UsageTrackingQueryCachingPolicy
- java.lang.Object
-
- org.apache.lucene.search.UsageTrackingQueryCachingPolicy
-
- All Implemented Interfaces:
QueryCachingPolicy
public class UsageTrackingQueryCachingPolicy extends java.lang.Object implements QueryCachingPolicy
AQueryCachingPolicy
that tracks usage statistics of recently-used filters in order to decide on which filters are worth caching.
-
-
Field Summary
Fields Modifier and Type Field Description private FrequencyTrackingRingBuffer
recentlyUsedFilters
private static int
SENTINEL
-
Constructor Summary
Constructors Constructor Description UsageTrackingQueryCachingPolicy()
Create a new instance with an history size of 256.UsageTrackingQueryCachingPolicy(int historySize)
Expert: Create a new instance with a configurable history size.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) int
frequency(Query query)
(package private) static boolean
isCostly(Query query)
private static boolean
isPointQuery(Query query)
protected int
minFrequencyToCache(Query query)
For a given filter, return how many times it should appear in the history before being cached.void
onUse(Query query)
Callback that is called every time that a cached filter is used.boolean
shouldCache(Query query)
Whether the givenQuery
is worth caching.private static boolean
shouldNeverCache(Query query)
-
-
-
Field Detail
-
SENTINEL
private static final int SENTINEL
- See Also:
- Constant Field Values
-
recentlyUsedFilters
private final FrequencyTrackingRingBuffer recentlyUsedFilters
-
-
Constructor Detail
-
UsageTrackingQueryCachingPolicy
public UsageTrackingQueryCachingPolicy(int historySize)
Expert: Create a new instance with a configurable history size. Beware of passing too large values for the size of the history, eitherminFrequencyToCache(org.apache.lucene.search.Query)
returns low values and this means some filters that are rarely used will be cached, which would hurt performance. OrminFrequencyToCache(org.apache.lucene.search.Query)
returns high values that are function of the size of the history but then filters will be slow to make it to the cache.- Parameters:
historySize
- the number of recently used filters to track
-
UsageTrackingQueryCachingPolicy
public UsageTrackingQueryCachingPolicy()
Create a new instance with an history size of 256. This should be a good default for most cases.
-
-
Method Detail
-
isPointQuery
private static boolean isPointQuery(Query query)
-
isCostly
static boolean isCostly(Query query)
-
shouldNeverCache
private static boolean shouldNeverCache(Query query)
-
minFrequencyToCache
protected int minFrequencyToCache(Query query)
For a given filter, return how many times it should appear in the history before being cached. The default implementation returns 2 for filters that need to evaluate against the entire index to build aDocIdSetIterator
, likeMultiTermQuery
, point-based queries orTermInSetQuery
, and 5 for other filters.
-
onUse
public void onUse(Query query)
Description copied from interface:QueryCachingPolicy
Callback that is called every time that a cached filter is used. This is typically useful if the policy wants to track usage statistics in order to make decisions.- Specified by:
onUse
in interfaceQueryCachingPolicy
-
frequency
int frequency(Query query)
-
shouldCache
public boolean shouldCache(Query query) throws java.io.IOException
Description copied from interface:QueryCachingPolicy
Whether the givenQuery
is worth caching. This method will be called by theQueryCache
to know whether to cache. It will first attempt to load aDocIdSet
from the cache. If it is not cached yet and this method returnstrue
then a cache entry will be generated. Otherwise an uncached scorer will be returned.- Specified by:
shouldCache
in interfaceQueryCachingPolicy
- Throws:
java.io.IOException
-
-