Class SearcherManager

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public final class SearcherManager
    extends ReferenceManager<IndexSearcher>
    Utility class to safely share IndexSearcher instances across multiple threads, while periodically reopening. This class ensures each searcher is closed only once all threads have finished using it.

    Use ReferenceManager.acquire() to obtain the current searcher, and ReferenceManager.release(G) to release it, like this:

     IndexSearcher s = manager.acquire();
     try {
       // Do searching, doc retrieval, etc. with s
     } finally {
     // Do not use s after this!
     s = null;

    In addition you should periodically call ReferenceManager.maybeRefresh(). While it's possible to call this just before running each query, this is discouraged since it penalizes the unlucky queries that need to refresh. It's better to use a separate background thread, that periodically calls ReferenceManager.maybeRefresh(). Finally, be sure to call ReferenceManager.close() once you are done.

    See Also:
    WARNING: This API is experimental and might change in incompatible ways in the next release.