【问题标题】:Lucene .NET not returning search resultsLucene .NET 不返回搜索结果
【发布时间】:2011-09-26 04:14:42
【问题描述】:

由于某种原因,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

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

【问题讨论】:

    标签: .net lucene lucene.net


    【解决方案1】:

    SimpleAnalyzer 使用LetterTokenizer,它只返回字母。

    考虑使用KeywordAnalyzer 代替id 字段。

    【讨论】:

    • 我很高兴这对你有用。顺便说一句,在 * 上,表达感激之情的一个好方法是点赞并接受答案。祝 Lucene.net 好运!