You must reopen your IndexReader to see recent changes to the index. But, IW.commit after each indexing op is very costly.
It's much better to get near-real-time readers, e.g. from a SearcherManager that you pass your IW instance too, after each set of changes that you now need to search. As long as you call SearcherManager.maybeRefreshBlocking after changes to the IW, the resulting reopened reader will reflect your index changes. Mike McCandless http://blog.mikemccandless.com On Thu, Jun 23, 2016 at 7:47 AM, Baskakov Daniel <gda...@gmail.com> wrote: > Originally i've posted the question at stackoverflow.com but without any > reply. So I hope someone can help me in the official list. > > I'm testing that dynamic changes of the domain model reflects at the Lucene > index. Special event listeners (synchronous, no multithreading here) are > executed when the domain model components change. Listeners update the > Lucene index: > > Document doc = createDocumentForComponent(domainModelComponent); > indexWriter.updateDocument(docTerm, doc); > indexWriter.commit(); > > Then I perform searching by a query that contains recently added changes. > Most of the time tests work perfect, but sometimes they fail (especially in > automated builds). > > I've tried to acquire an IndexSearcher by different ways: create a new > searcher on the same Directory or obtain it via SearcherManager. > > Is there a way to made recent index changes available to index searcher > with 100% confidence? >