What is the best way to achieve Lucene real-time indexing?
Lucene has a feature called near-real-time search to address exactly this need.
It requires that your IndexReader is in the same JVM as your IndexWriter.
You make changes with the IndexWriter, and then open a reader directly from the writer using IndexReader.open(writer), or on older Lucene releases writer.getReader(). This call will normally be very fast (in proportion to how many changes you've made since last opening a reader) as it bypasses the costly commit normally required for opening a reader. It's able to search the un-committed changes in the writer.
This reader still searches a point-in-time snapshot from the writer, ie all changes as of when you opened it.
Obtain an index reader from the index writer.
Update: Looks like the current method is to open a directory reader using an index writer object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With