I am using Lucene 6.6.0 and I would like to use the near real-time search feature of Lucene. However, I could not manage to implement it. The way I try to get the feature is as follows:
I initialize an IndexReader instance:
this.reader = DirectoryReader.open(this.directory);
Let's assume some changes have been made in the index via an IndexWriter instance. Then, if I understand correctly, I need a second instance of IndexReader to commit updates:
this.newReader = DirectoryReader.openIfChanged(this.reader);
if (this.newReader != null) {
// Update the IndexSearcher with the new IndexReader instance
this.searcher = new IndexSearcher(this.newReader);
this.reader.close();
}
The issue here is that the code does not compile because of the following error: The method openIfChanged(DirectoryReader) in the type DirectoryReader is not applicable for the arguments (IndexReader)
.
How should I update the IndexReader
then ?
Secondly, if I update the index again, I will need another IndexReader instance, won't I ? Would the most optimal way to update the index freely during the execution of the program be by switching between 2 IndexReader instances after each update ?
Thank you.