Hello,

I am quite confused about the Lucene NRT feature. And there are not many
examples out there.

My understanding is we can create an DirectoryReader from a IndexWriter.
Whenever IndexWriter changes the index, we can use DirectoryReader to
detect the changes and recreate DirectoryReader if necessary.

The sequence is:

IndexWriter w = ...;
DirectoryReader r = new IndexSearcher(DirectoryReader.open(w, true));
IndexSearcher s = new IndexSearcher(r);
// do some search
s.search(...);
// update index
w.removeDocuments(new Term("id",id_to_delete));
// assume commit() is optional, we probably can skip the next statement
w.commit();
// reopen index if necessary
r = DirectoryReader.openIfChanged((DirectoryReader) s.getIndexReader());
if (r != null) {
    s.getIndexReader().close();
    s = new IndexSearcher(r);
}
// now it supposed to see the updates
s.search(...);

However, I found s still can find id_to_delete in the last step. Am I
missing something here?

Thanks.

Reply via email to