openIfChanged
If the index has changed since the provided reader was opened, open and return a new reader; else, return null. The new reader, if not null, will be the same type of reader as the previous one, ie an NRT reader will open a new NRT reader etc.
This method is typically far less costly than opening a fully new DirectoryReader * as it shares resources (for example sub-readers) with the provided DirectoryReader, when possible.
The provided reader is not closed (you are responsible for doing so); if a new reader is returned you also must eventually close it. Be sure to never close a reader while other threads are still using it; see SearcherManager to simplify managing this.
Return
null if there are no changes; else, a new DirectoryReader instance which you must eventually close
Throws
if the index is corrupt
if there is a low-level IO error
If the IndexCommit differs from what the provided reader is searching, open and return a new reader; else, return null.
See also
.openIfChanged
Expert: If there changes (committed or not) in the IndexWriter versus what the provided reader is searching, then open and return a new IndexReader searching both committed and uncommitted changes from the writer; else, return null (though, the current implementation never returns null).
This provides "near real-time" searching, in that changes made during an IndexWriter session can be quickly made available for searching without closing the writer or calling IndexWriter.commit.
It's near real-time because there is no hard guarantee on how quickly you can get a new reader after making changes with IndexWriter. You'll have to experiment in your situation to determine if it's fast enough. As this is a new and experimental feature, please report back on your findings so we can learn, improve and iterate.
The very first time this method is called, this writer instance will make every effort to pool the readers that it opens for doing merges, applying deletes, etc. This means additional resources (RAM, file descriptors, CPU time) will be consumed.
For lower latency on reopening a reader, you should call to pre-warm a newly merged segment before it's committed to the index. This is important for minimizing index-to-search delay after a large merge.
If an addIndexes* call is running in another thread, then this reader will only search those segments from the foreign index that have been successfully copied over, so far.
NOTE: Once the writer is closed, any outstanding readers may continue to be used. However, if you attempt to reopen any of those readers, you'll hit an [ ].
Return
DirectoryReader that covers entire index plus all changes made so far by this IndexWriter instance, or null if there are no new changes
Parameters
The IndexWriter to open from
Throws
if there is a low-level IO error