searchlucenenear-real-time

Lucene Near Realtime Search


I would like to improve the speed of my search system, by using some features like the "Near realtime search", making faster the opening of an index.

Who can tell me what are the differences and advantages of using one or the other of the following pieces of code:

IndexReader newIndexReader = IndexReader.openIfChanged(oldReader);

and

IndexWriter writer; // create an IndexWriter here
...
IndexReader reader = writer.getReader();

Note that in the first case i don't need that the indexWriter is in the same process of the IndexReader.


Solution

  • First of all, writer.getReader() is only available in 3.6 release but absent in all v4 (4.0, 4.1, ...) releases. So you shouldn't be using it if you care about maintainability.

    Now, to answer your question. writer.getReader() flushes all pending writes and unconditionally opens a new reader (plus there are some other limitations - see method javadoc). IndexReader.openIfChanged(oldReader) only opens a new reader if there were any changes made, otherwise returns old reader.

    To my taste, opening a reader from writer is also conceptually wrong (there used to be other cases in Lucene having this problem, e.g. it used to be possible to delete documents using reader).

    If you are choosing between the two, I think there's no doubt which method to use.