Here is the code:
Try Dim util As New IndexerUtil() Dim dir As Lucene.Net.Store.Directory = FSDirectory.Open(New DirectoryInfo(util.getIndexDir())) Dim indexWriter As New IndexWriter(dir, New SimpleAnalyzer(), indexWriter.MaxFieldLength.UNLIMITED) Dim numDocs As Integer = indexWriter.NumDocs() indexWriter.DeleteDocuments(New Term("id", insightId)) indexWriter.Optimize() indexWriter.Commit() indexWriter.Close() numDocs = indexWriter.NumDocs() Catch ex As Exception LOG.Error("Could not remove insight " + insightId + " from index", ex) End Try
numDocs = 85 both times
I also have a small gui application that I wrote that reads the index and prints documents in a good format. A document with an id field that is equal to insightId definitely exists, and STILL exists after "deletion".
Here's how to create an id field
doc.Add(New Field("id", insightID, Field.Store.YES, Field.Index.ANALYZED))
source share