diff --git a/lucene/core/src/java/org/apache/lucene/search/SearcherManager.java b/lucene/core/src/java/org/apache/lucene/search/SearcherManager.java index 072c13d9274..1ec9d70a46b 100644 --- a/lucene/core/src/java/org/apache/lucene/search/SearcherManager.java +++ b/lucene/core/src/java/org/apache/lucene/search/SearcherManager.java @@ -114,16 +114,15 @@ public SearcherManager(Directory dir, SearcherFactory searcherFactory) throws IO } /** - * Creates and returns a new SearcherManager from an existing {@link DirectoryReader}. Note that + * Creates and returns a new SearcherManager from an existing {@link IndexReader}. Note that * this steals the incoming reference. * - * @param reader the DirectoryReader. + * @param reader the IndexReader. * @param searcherFactory An optional {@link SearcherFactory}. Pass null if you don't * require the searcher to be warmed before going live or other custom behavior. * @throws IOException if there is a low-level I/O error */ - public SearcherManager(DirectoryReader reader, SearcherFactory searcherFactory) - throws IOException { + public SearcherManager(IndexReader reader, SearcherFactory searcherFactory) throws IOException { if (searcherFactory == null) { searcherFactory = new SearcherFactory(); } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSearcherManager.java b/lucene/core/src/test/org/apache/lucene/search/TestSearcherManager.java index e44855afe87..ca858635e54 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSearcherManager.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSearcherManager.java @@ -28,20 +28,13 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.index.ConcurrentMergeScheduler; -import org.apache.lucene.index.DirectoryReader; -import org.apache.lucene.index.FilterDirectoryReader; -import org.apache.lucene.index.FilterLeafReader; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.index.LeafReader; -import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.Term; +import org.apache.lucene.document.TextField; +import org.apache.lucene.index.*; import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.store.Directory; import org.apache.lucene.tests.analysis.MockAnalyzer; import org.apache.lucene.tests.index.RandomIndexWriter; +import org.apache.lucene.util.English; import org.apache.lucene.tests.index.ThreadedIndexingAndSearchingTestCase; import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.lucene.tests.util.LuceneTestCase.SuppressCodecs; @@ -546,6 +539,43 @@ public void testCustomDirectoryReader() throws Exception { dir.close(); } + // LUCENE-13975 + public void testMultiReaderReader() throws Exception { + Directory dir = newDirectory(); + RandomIndexWriter w = new RandomIndexWriter(random(), dir); + DirectoryReader nrtReader = w.getReader(); + + Directory dir2 = newDirectory(); + RandomIndexWriter w2 = new RandomIndexWriter(random(), dir2); + DirectoryReader nrtReader2 = w2.getReader(); + + MultiReader reader = new MultiReader(nrtReader, nrtReader2); + + SearcherManager mgr = new SearcherManager(reader, null); + for(int i=0;i<10;i++) { + Document d = new Document(); + d.add(new TextField("contents", English.intToEnglish(i), Field.Store.NO)); + w.addDocument(new Document()); + + Document d2 = new Document(); + d2.add(new TextField("contents", English.intToEnglish(i+10), Field.Store.NO)); + w2.addDocument(new Document()); + } + + mgr.maybeRefresh(); + IndexSearcher s = mgr.acquire(); + try { + assertTrue(s.getIndexReader() instanceof MultiReader); + assertEquals(s.count(new MatchAllDocsQuery()), 20); + } finally { + mgr.release(s); + } + + mgr.close(); + w.close(); + dir.close(); + } + public void testPreviousReaderIsPassed() throws IOException { final Directory dir = newDirectory(); final IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());