检查文档是否存在于Index(Lucene.NET)的条件 [英] Condition to check whether document exists in Index (Lucene.NET)

查看:244
本文介绍了检查文档是否存在于Index(Lucene.NET)的条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Lucene.NET,我想检查文档是否包含在索引中,所以如果是,我不需要将其存储在索引,但我可以跳过它。我读了一些有相同问题的问题,但他们都处理删除和更新与新的文档。我不想这样做,因为文档将包含完全相同的数据,它是没有用再次存储。我有一个字段,作为一个称为URL的ID,其中每个文档包含其特定的URL。因此,我有一个方法来识别具体的文件,我只是不知道应该使用什么条件。

I am using Lucene.NET and I would like to check before whether a document is contained in the index, so that if it is, I do not need to store it in the index, but I can skip it. I've read some questions that had the same problem, but they all dealt with deleting and updating it with the new document. I don't want to have to do that since the document will contain the exact same data and it would be useless to store it again. I have a field that acts as an ID called URL where each document contains its specific URL. therefore there is a way for me to identify the specific document, I just don't know what condition I should use.

任何帮助?

推荐答案

我会使用这样的:

IndexReader reader;
Term indexTerm = new Term(FieldNames.UniqueId, itemId.ToString());
TermDocs docs = reader.TermDocs(indexTerm);
if (docs.Next())
{
    continue;
}

这篇关于检查文档是否存在于Index(Lucene.NET)的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆