Is it possible to undelete a document in Lucene.net index?
I have the need to delete documents from my Lucene index and then be able to re-add them later. It seems that if I mark a document as delet开发者_如何学编程ed and then attempt to add it again.. the document remains deleted. How can "undelete" a document?
This is how I am marking a document as "deleted":
Term = new Tearm("id", Id.Value);
IndexSearcher.reader.DeleteDocuments(term);
IndexSearcher.reader.Close();
So if I would like to "activate" this document again.. how would I do it?
Thanks!
I'm not familiar with Lucene.Net, but Java version has IndexReader.undeleteAll()
method.
Lucene's deletions are soft-deletions. That means, when documents are deleted, they are marked for deletions. Only when index is optimized, the deleted documents are purged from the index. The list of documents is maintained in a .del file in the index directory. undeleteAll()
method purges the contents of the file to make those documents active again. (Do not try to delete this file manually, as reference to this file is maintained in the index segment files.)
You cannot undelete a subset of documents. You have to undelete all the documents. You can emulate the required functionality by getting list of all the deleted documents, invoke undeleteAll()
, and then again delete the documents except the one(s) that you wish to preserve.
I think you might be better off not deleting the docs but rated adding a field to mark them as deleted and filtering that field out of your queries. Unless someone asks form deleted documents too then you can easily show them.
精彩评论