Lucene .NET 不返回搜索结果

发布于 2024-11-18 01:53:38 字数 743 浏览 0 评论 0原文

由于某种原因,lucene 没有返回任何应该返回的结果。这是“搜索”代码

Dim util As New IndexerUtil()
Dim dir As Lucene.Net.Store.Directory = FSDirectory.Open(New DirectoryInfo(util.getIndexDir()))
Dim indexSearcher As New IndexSearcher(dir, False)
Dim indexWriter As New IndexWriter(dir, New SimpleAnalyzer(), False, indexWriter.MaxFieldLength.UNLIMITED)

Dim term As New Term("id", "346")
Dim query As New TermQuery(term)
Dim topDocs As TopDocs = indexSearcher.Search(query, 100)

topDocs 中没有 ScoreDocs(结果)。我知道索引中有一个文档,其中 id 字段等于 346,但由于某种原因搜索没有找到它。这是“id”字段的创建方式,

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

我还有其他字段可供搜索,并且这些字段工作正常(例如,如果我在主题字段上搜索,我会得到我应该得到的结果)

For some reason lucene is not returning any results when it should be. Here is the 'search' code

Dim util As New IndexerUtil()
Dim dir As Lucene.Net.Store.Directory = FSDirectory.Open(New DirectoryInfo(util.getIndexDir()))
Dim indexSearcher As New IndexSearcher(dir, False)
Dim indexWriter As New IndexWriter(dir, New SimpleAnalyzer(), False, indexWriter.MaxFieldLength.UNLIMITED)

Dim term As New Term("id", "346")
Dim query As New TermQuery(term)
Dim topDocs As TopDocs = indexSearcher.Search(query, 100)

There are no scoreDocs (results) in topDocs. I know for a fact that there is a document in the index where the id field is equal to 346 however for some reason the search is not finding it. Here is how the "id" field is being created

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

I have other fields to search on and those work fine (e.g. if I search on the subject field I get the results I should)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

吻泪 2024-11-25 01:53:38

SimpleAnalyzer 使用 LetterTokenizer,仅返回字母。

考虑使用 KeywordAnalyzer 代替id 字段。

SimpleAnalyzer uses LetterTokenizer, which only returns letters.

Consider using the KeywordAnalyzer instead for the id field.

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