Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multireader Support in Searcher Manager #13976

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>null</code> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Loading