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 {
       manager.release(s);
     }
     // 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 do the reopen. It's better to use a separate background thread, that periodically calls maybeReopen. Finally, be sure to call ReferenceManager.close() once you are done.

    See Also:
    SearcherFactory