Lucene .NET IndexWriter 删除文档不工作

发布于 2024-11-18 04:04:34 字数 918 浏览 0 评论 0原文

这是代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

故事还在继续 2024-11-25 04:04:34

正如您可能在最近的帖子中发现的那样,您的 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.

薄凉少年不暖心 2024-11-25 04:04:34

由于 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?

小嗲 2024-11-25 04:04:34

您应该创建一个新的 IndexWriter,而不是在关闭的 IndexWriter 上计数文档。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文