Pini Salim
Pini Salim

Reputation: 171

Lucene's IndexWriter clarifications

In attemp to find a bug in our project, I found myself with few questions about Lucene's indexing API with no answer: The first one is related to the following snippet:

IndexWriter writer = //open an index for writings.
// ... do some heavy updates (inserts and deletes) to the index using 'writer'

IndexReader reader = writer.GetReader();
long[] idsArray = Field_Cache_Fields.DEFAULT.GetLongs(reader, "ID_Field");  
//under the assumption that ALL indexed documents contain field with the name "ID_Field".

Is it promised by Lucene's API that the reader that I get will ALWAYS get the updated, even though uncommited index? Just to make sure my answer is clear: every deleted doc WONT be seen by the reader and every added doc WILL be..

The second question is related to the next snippet:

IndexWriter writer = //open an index for writing, but dont change a thing - just commit meta data.
writer.Commit["Hello"] = "World";
writer.Commit();

Is it promised that the metadata will be commited to the index, eventhough I opened it with no actual change to the index?

In both of the question I will be happy to know what was meant by the API, and also if some one knows about issues (any bugs?) specific with Lucene .Net 2.9.2

thanks guys!

Upvotes: 1

Views: 653

Answers (1)

Jf Beaulac
Jf Beaulac

Reputation: 5246

First Question: yes

From the doc:

Expert: returns a readonly reader, covering all committed as well as un-committed changes to the index. 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 nor calling #commit . Note that this is functionally equivalent to calling {#commit} and then using IndexReader#open to open a new reader. But the turarnound time of this method should be faster since it avoids the potentially costly #commit .

Upvotes: 1

Related Questions