Class CachingCollectorManager<C extends Collector,R>

java.lang.Object
org.apache.lucene.search.CachingCollectorManager<C,R>
All Implemented Interfaces:
CollectorManager<CachingCollector,R>

public class CachingCollectorManager<C extends Collector,R> extends Object implements CollectorManager<CachingCollector,R>
A CollectorManager that wraps a delegate CollectorManager and caches all collected documents (and optionally scores) per slice, so they can be replayed to a second-pass CollectorManager without re-running the query.

One CachingCollector is created per slice. During replay(org.apache.lucene.search.CollectorManager<C2, R2>), each cached slice is replayed into a fresh second-pass collector, and all second-pass collectors are reduced together. This works correctly with both sequential and concurrent search.

Example usage:

 CachingCollectorManager<C1, R1> caching = new CachingCollectorManager<>(
     firstPassManager, cacheScores, maxRAMMB, null);
 R1 firstResult = searcher.search(query, caching);

 if (caching.isCached()) {
   R2 secondResult = caching.replay(secondPassManager);
 } else {
   // cache overflowed — re-run the query
   R2 secondResult = searcher.search(query, secondPassManager);
 }
 
WARNING: This API is experimental and might change in incompatible ways in the next release.