eshes searcher every 5 seconds when nobody is waiting, and up to 100 msec delay // when somebody is waiting: NRTManagerReopenThread reopenThread = new NRTManagerReopenThread(manager, 5.0, 0.1); reopenThread.setName("NRT Reopen Thread"); reopenThread.setPriority(Math.min(Thread.currentThread().getPriority()+2, Thread.MAX_PRIORITY)); reopenThread.setDaemon(true); reopenThread.start(); Then, for each incoming query, do this:
// For each incoming query: IndexSearcher searcher = manager.get(); try { // Use searcher to search... } finally { manager.release(searcher); }
You should make changes using the
NRTManager
; if you later need to obtain a searcher reflecting those changes:
// ... or updateDocument, deleteDocuments, etc: long gen = manager.addDocument(...); // Returned searcher is guaranteed to reflect the just added document IndexSearcher searcher = manager.get(gen); try { // Use searcher to search... } finally { manager.release(searcher); }
When you are done be sure to close both the manager and the reopen thrad:
reopenThread.close(); manager.close();
@lucene.experimental