lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <luc...@mikemccandless.com>
Subject Re: Detect index changes
Date Thu, 17 Oct 2013 10:54:14 GMT
Your understanding is correct, and after reopen you should see the
document deleted, so I'm not sure offhand why you aren't.

BTW it's w.deleteDocuments not w.removeDocuments.

And you don't need to commit in order to see changes in the reopened
NRT reader (this is the whole point: commit is very costly, and is
about "durability", i.e., ensuring your changes are written through to
stable storage so they can survive things like sudden OS crash, power
loss, etc.).

Are you sure the id field is indexed, as a StringField (so it is not
tokenized)?  When you do a TermQuery(new Term("id", id_to_delete))
beforehand, does it find the one document you want to delete?

Can you boil the case down to a small testcase?

Mike McCandless

http://blog.mikemccandless.com


On Thu, Oct 17, 2013 at 1:10 AM, Alice Wong <airwaywong@gmail.com> wrote:
> Hello,
>
> I am quite confused about the Lucene NRT feature. And there are not many
> examples out there.
>
> My understanding is we can create an DirectoryReader from a IndexWriter.
> Whenever IndexWriter changes the index, we can use DirectoryReader to
> detect the changes and recreate DirectoryReader if necessary.
>
> The sequence is:
>
> IndexWriter w = ...;
> DirectoryReader r = new IndexSearcher(DirectoryReader.open(w, true));
> IndexSearcher s = new IndexSearcher(r);
> // do some search
> s.search(...);
> // update index
> w.removeDocuments(new Term("id",id_to_delete));
> // assume commit() is optional, we probably can skip the next statement
> w.commit();
> // reopen index if necessary
> r = DirectoryReader.openIfChanged((DirectoryReader) s.getIndexReader());
> if (r != null) {
>     s.getIndexReader().close();
>     s = new IndexSearcher(r);
> }
> // now it supposed to see the updates
> s.search(...);
>
> However, I found s still can find id_to_delete in the last step. Am I
> missing something here?
>
> Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message