下面是代碼:Lucene的.NET的IndexWriter DeleteDocuments不工作
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這兩個時間
我也有一個小的GUI應用程序我寫了讀取索引並打印文檔出一個不錯的格式。具有等於insightId的id字段的文檔肯定存在,並且在「刪除」之後存在。
下面是id字段正在創建
doc.Add(New Field("id", insightID, Field.Store.YES, Field.Index.ANALYZED)) //insightID is an integer
你在創建索引時如何創建id字段?你可以發佈代碼嗎?另外,代碼是否會拋出任何異常? –