Reputation: 2807
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?
Upvotes: 4
Views: 2282
Reputation: 237
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;
}
Upvotes: 5