Lucene.NET IndexWriter DeleteDocuments not working

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)) //insightID is an integer 
+4
source share
3 answers

As you probably discovered with a later post , your identifier is not indexed correctly because SimpleAnalyzer uses a LetterTokenizer that returns only letters.

Use KeywordAnalyzer instead of id field.

+6
source

Since SimpleAnalyzer converts the input text to lowercase, the subscripts will be listed in the index. Are you sure the "insightId" is also at the bottom?

0
source

You should create a new IndexWriter instead of counting documents in private.

0
source

All Articles