org.apache.lucene.search

## Class UsageTrackingFilterCachingPolicy

- java.lang.Object
- - org.apache.lucene.search.UsageTrackingFilterCachingPolicy

- All Implemented Interfaces:
    FilterCachingPolicy

      public final class UsageTrackingFilterCachingPolicy
      extends Object
      implements FilterCachingPolicy

  A `FilterCachingPolicy` that tracks usage statistics of recently-used filters in order to decide on which filters are worth caching. It also uses some heuristics on segments, filters and the doc id sets that they produce in order to cache more aggressively when the execution cost significantly outweighs the caching overhead.
  WARNING: This API is experimental and might change in incompatible ways in the next release.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.apache.lucene.search.FilterCachingPolicy

      `FilterCachingPolicy.CacheOnLargeSegments`

  - ### Field Summary

    - ### Fields inherited from interface org.apache.lucene.search.FilterCachingPolicy

      `ALWAYS_CACHE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `UsageTrackingFilterCachingPolicy()` Create a new instance with sensible defaults.
    `UsageTrackingFilterCachingPolicy(float minSizeRatio, int historySize, int minFrequencyCostlyFilters, int minFrequencyCheapFilters, int minFrequencyOtherFilters)` Create a new instance.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `onUse(Filter filter)` Callback that is called every time that a cached filter is used.
    `boolean` | `shouldCache(Filter filter, LeafReaderContext context, DocIdSet set)` Whether the given `DocIdSet` should be cached on a given segment.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### UsageTrackingFilterCachingPolicy

          public UsageTrackingFilterCachingPolicy(float minSizeRatio,
                                          int historySize,
                                          int minFrequencyCostlyFilters,
                                          int minFrequencyCheapFilters,
                                          int minFrequencyOtherFilters)

      Create a new instance.
      Parameters:
        `minSizeRatio` - the minimum size ratio for segments to be cached, see `FilterCachingPolicy.CacheOnLargeSegments`
        `historySize` - the number of recently used filters to track
        `minFrequencyCostlyFilters` - how many times filters whose `getDocIdSet` method is expensive should have been seen before being cached
        `minFrequencyCheapFilters` - how many times filters that produce `DocIdSet`s that are cheap to cached should have been seen before being cached
        `minFrequencyOtherFilters` - how many times other filters should have been seen before being cached

    - #### UsageTrackingFilterCachingPolicy

          public UsageTrackingFilterCachingPolicy()

      Create a new instance with sensible defaults.

  - ### Method Detail

    - #### onUse

          public void onUse(Filter filter)

      Description copied from interface: `FilterCachingPolicy`
      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 interface `FilterCachingPolicy`

    - #### shouldCache

          public boolean shouldCache(Filter filter,
                            LeafReaderContext context,
                            DocIdSet set)
                              throws IOException

      Description copied from interface: `FilterCachingPolicy`
      Whether the given `DocIdSet` should be cached on a given segment. This method will be called on each leaf context to know if the filter should be cached on this particular leaf. The filter cache will first attempt to load a `DocIdSet` from the cache. If it is not cached yet and this method returns `true` then a cache entry will be generated. Otherwise an uncached set will be returned.
      Specified by:
        `shouldCache` in interface `FilterCachingPolicy`
      Throws:
        `IOException`

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.