views:

580

answers:

1

I'm developing a Desktop Search Engine in VB 9 using Lucene.NET

I wish to delete and create a new entry for a file that is updated.

The Index stores complete file path and the last modified date.

doc.Add(New Field("path", filepath, Field.Store.YES, Field.Index.UN_TOKENIZED))
doc.Add(New Field("modified", New FileInfo(filepath).LastWriteTime, Field.Store.YES, Field.Index.UN_TOKENIZED))
.
.

I'm using the IndexReader to check if a file is present in the Index (to avoid re-indexing the same files).

Dim reader As IndexReader = IndexReader.Open(SearchForm.IndexFolderTextBox.Text)

If reader.DocFreq(New Term("path", filepath)) = 0 Then
     addFile(filepath)
End If

reader.Close()

I have the following doubts:

  1. How do I use the value in the modified field to check if the Index entry for a particular file is old? What function of IndexReader will allow me to do this?

  2. How do I get the document number (docNum) for the function deleteDocument()

+1  A: 

To answer your second questions, use the following IndexReader method:

public int deleteDocuments(Term term)

so you won't need the document number.

KenE