Class ReaderManager

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public final class ReaderManager
    extends ReferenceManager<DirectoryReader>
    Utility class to safely share DirectoryReader instances across multiple threads, while periodically reopening. This class ensures each reader is closed only once all threads have finished using it.
    See Also:
    SearcherManager
    • Constructor Detail

      • ReaderManager

        public ReaderManager​(IndexWriter writer)
                      throws java.io.IOException
        Creates and returns a new ReaderManager from the given IndexWriter.
        Parameters:
        writer - the IndexWriter to open the IndexReader from.
        Throws:
        java.io.IOException - If there is a low-level I/O error
      • ReaderManager

        public ReaderManager​(IndexWriter writer,
                             boolean applyAllDeletes,
                             boolean writeAllDeletes)
                      throws java.io.IOException
        Expert: creates and returns a new ReaderManager from the given IndexWriter, controlling whether past deletions should be applied.
        Parameters:
        writer - the IndexWriter to open the IndexReader from.
        applyAllDeletes - If true, all buffered deletes will be applied (made visible) in the IndexSearcher / DirectoryReader. If false, the deletes may or may not be applied, but remain buffered (in IndexWriter) so that they will be applied in the future. Applying deletes can be costly, so if your app can tolerate deleted documents being returned you might gain some performance by passing false. See DirectoryReader.openIfChanged(DirectoryReader, IndexWriter, boolean).
        writeAllDeletes - If true, new deletes will be forcefully written to index files.
        Throws:
        java.io.IOException - If there is a low-level I/O error
      • ReaderManager

        public ReaderManager​(Directory dir)
                      throws java.io.IOException
        Creates and returns a new ReaderManager from the given Directory.
        Parameters:
        dir - the directory to open the DirectoryReader on.
        Throws:
        java.io.IOException - If there is a low-level I/O error
      • ReaderManager

        public ReaderManager​(DirectoryReader reader)
                      throws java.io.IOException
        Creates and returns a new ReaderManager from the given already-opened DirectoryReader, stealing the incoming reference.
        Parameters:
        reader - the directoryReader to use for future reopens
        Throws:
        java.io.IOException - If there is a low-level I/O error