简体   繁体   English

是否可以取消删除Lucene.net索引中的文档?

[英]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. 我需要从我的Lucene索引中删除文档,然后以后可以重新添加它们。 It seems that if I mark a document as deleted 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.Net,但是Java版本具有IndexReader.undeleteAll()方法。

Lucene's deletions are soft-deletions. Lucene的删除是软删除。 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. 文档列表保存在索引目录中的.del文件中。 undeleteAll() method purges the contents of the file to make those documents active again. undeleteAll()方法清除文件的内容,以使这些文档再次处于活动状态。 (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. 您可以通过获取所有已删除文档的列表,调用undeleteAll() ,然后再次删除除您要保留的文档以外的文档,来模拟所需的功能。

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. 除非有人也要求删除表格,否则您可以轻松显示它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM