ryoung
ryoung

Reputation: 846

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 little gui app I wrote which reads the index and prints the docs out in a nice format. The doc with the id field that equals insightId definitely exists and STILL exists after the "deletion".

Here is how the id field is being created

doc.Add(New Field("id", insightID, Field.Store.YES, Field.Index.ANALYZED)) //insightID is an integer

Upvotes: 4

Views: 1810

Answers (3)

agent-j
agent-j

Reputation: 27953

As you have probably discovered with your more recent post, your ID column is not being indexed correctly because SimpleAnalyzer uses LetterTokenizer, which only returns letters.

Consider using the KeywordAnalyzer instead for the id field.

Upvotes: 6

mathieu
mathieu

Reputation: 31202

You should create a new IndexWriter instead of counting documents on a closed one.

Upvotes: 0

Anonymous
Anonymous

Reputation: 144

Since SimpleAnalyzer converts input text to lowercase, you will have lowercased terms in the index. Are you sure that "insightId" is also lowercased?

Upvotes: 0

Related Questions