Condition to check whether document exists in Index (Lucene.NET)

耗尽温柔 提交于 2019-12-10 15:48:55

问题


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.

Any help?


回答1:


I would use something like this:

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


来源:https://stackoverflow.com/questions/5714288/condition-to-check-whether-document-exists-in-index-lucene-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!