Lucene .NET IndexWriter 删除文档不工作
这是代码:
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 应用程序,它读取索引并以良好的格式打印文档。 id 字段等于 InsightId 的文档肯定存在,并且在“删除”后仍然存在。
这是 id 字段的创建方式
doc.Add(New Field("id", insightID, Field.Store.YES, Field.Index.ANALYZED)) //insightID is an integer
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如您可能在最近的帖子中发现的那样,您的 ID 列不是被正确索引,因为 SimpleAnalyzer 使用 LetterTokenizer ,仅返回字母。
考虑使用 KeywordAnalyzer 代替
id
字段。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.由于 SimpleAnalyzer 将输入文本转换为小写,因此索引中将包含小写术语。
您确定“insightId”也是小写吗?
Since SimpleAnalyzer converts input text to lowercase, you will have lowercased terms in the index.
Are you sure that "insightId" is also lowercased?
您应该创建一个新的 IndexWriter,而不是在关闭的 IndexWriter 上计数文档。
You should create a new IndexWriter instead of counting documents on a closed one.