I am going to write a real-time search application with distributed indexes. Now I am wondering what is the correct approach to implementing a search on multiple indexes:
I read about MultiSearcher, so one of them would be as follows:
IndexSearcher[] indexSearchers = new IndexSearcher[indexCount]; for (int i = 0; i < indexCount; i++) { File directory = new File(indexdir, String.valueOf(i)); IndexWriter indexWriter = new IndexWriter(FSDirectory.open(directory), analyzer, IndexWriter.MaxFieldLength.LIMITED); IndexReader indexReader = indexWriter.getReader(); indexSearchers[i] = new IndexSearcher(indexReader); } MultiSearcher searcher = new MultiSearcher(indexSearchers);
But, as I see it, this is also possible:
IndexReader[] indexReader = new IndexReader[indexCount]; for (int i = 0; i < indexCount; i++) { File directory = new File(indexdir, String.valueOf(i)); IndexWriter indexWriter = new IndexWriter(FSDirectory.open(directory), analyzer, IndexWriter.MaxFieldLength.LIMITED); indexReader[i] = indexWriter.getReader(); } IndexSearcher searcher = new IndexSearcher(new MultiReader(indexReader));
Is there a significant difference between the two statements? The second one will be easier to process if the reader does not have data, because I can just call MultiReader.reopen () instead of repeating all IndexReaders, reopen them, and not create new IndexSearchers ...
source share