[英]Lucene.NET - Can't delete docs using IndexWriter
我正在接管一个项目,所以我还在学习这个。 该项目使用Lucence.NET。 我也不知道这个功能是否正确。 无论如何,我实例化:
var writer = new IndexWriter(directory, analyzer, false);
对于具体文件,我打电话给:
writer.DeleteDocuments(new Term(...));
最后,我正在调用通常的writer.Optimize(),writer.Commit()和writer.Close()。
Term对象中的字段是Guid,转换为字符串(.ToString(“D”)),并使用Field.Store.YES和Field.Index.NO存储在文档中。
但是,通过这些设置,我似乎无法删除这些文档。 目标是删除,然后添加更新的版本,所以我得到相同文档的重复。 如果需要,我可以提供更多代码/解释。 有任何想法吗? 谢谢。
该字段必须编入索引。 如果某个字段未编入索引,则其字词不会显示在枚举中。
我认为你处理作家的方式没有任何问题。
听起来好像传递给DeleteDocuments的术语没有返回任何文档。 您是否尝试使用相同的术语进行查询以查看是否返回任何结果?
此外,如果您的目标是简单地重新创建文档,则可以调用UpdateDocument:
// Updates a document by first deleting the document(s) containing term and
// then adding the new document. The delete and then add are atomic as seen
// by a reader on the same index (flush may happen only after the add). NOTE:
// if this method hits an OutOfMemoryError you should immediately close the
// writer. See above for details.
您可能还想查看SimpleLucene(http://simplelucene.codeplex.com) - 它使基本的Lucene任务变得容易一些。
[更新]不确定我是如何错过它但@Shashikant Kore是正确的,您需要确保该字段已编入索引,否则您的术语查询将不会返回任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.