org.apache.lucene.search

## Class FilterCachingPolicy.CacheOnLargeSegments

- java.lang.Object
- - org.apache.lucene.search.FilterCachingPolicy.CacheOnLargeSegments

- All Implemented Interfaces:
    FilterCachingPolicy
  Enclosing interface:
    FilterCachingPolicy

      public static class FilterCachingPolicy.CacheOnLargeSegments
      extends Object
      implements FilterCachingPolicy

  A simple policy that only caches on the largest segments of an index. The reasoning is that these segments likely account for most of the execution time of queries and are also more likely to stay around longer than small segments, which makes them more interesting for caching.

- - ### Nested Class Summary

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

      `FilterCachingPolicy.CacheOnLargeSegments`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static FilterCachingPolicy.CacheOnLargeSegments` | `DEFAULT` `FilterCachingPolicy.CacheOnLargeSegments` instance that only caches on segments that account for more than 3% of the total index size.

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

      `ALWAYS_CACHE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FilterCachingPolicy.CacheOnLargeSegments(float minSizeRatio)` Create a `FilterCachingPolicy.CacheOnLargeSegments` instance that only caches on a given segment if its number of documents divided by the total number of documents in the index is greater than or equal to `minSizeRatio`.

  - ### 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`

- - ### Field Detail

    - #### DEFAULT

          public static final FilterCachingPolicy.CacheOnLargeSegments DEFAULT

      `FilterCachingPolicy.CacheOnLargeSegments` instance that only caches on segments that account for more than 3% of the total index size. This should guarantee that all segments from the upper `tier` will be cached while ensuring that at most `33` segments can make it to the cache (given that some implementations such as `LRUFilterCache` perform better when the number of cached segments is low).

  - ### Constructor Detail

    - #### FilterCachingPolicy.CacheOnLargeSegments

          public FilterCachingPolicy.CacheOnLargeSegments(float minSizeRatio)

      Create a `FilterCachingPolicy.CacheOnLargeSegments` instance that only caches on a given segment if its number of documents divided by the total number of documents in the index is greater than or equal to `minSizeRatio`.

  - ### 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.