ryo*_*ung 4 .net lucene lucene.net
这是代码:
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
Run Code Online (Sandbox Code Playgroud)
两次都是numDocs = 85
我还有一个我写的小gui应用程序,它读取索引并以漂亮的格式打印文档.具有等于insightId的id字段的doc肯定存在,并且在"删除"之后存在STILL.
以下是如何创建id字段
doc.Add(New Field("id", insightID, Field.Store.YES, Field.Index.ANALYZED)) //insightID is an integer
Run Code Online (Sandbox Code Playgroud)
正如您可能在最近的帖子中发现的那样,您的ID列未被正确编入索引,因为SimpleAnalyzer使用LetterTokenizer,它只返回字母.
考虑使用KeywordAnalyzer代替id字段.
| 归档时间: |
|
| 查看次数: |
1753 次 |
| 最近记录: |