Lucene .NET 不返回搜索结果
由于某种原因,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SimpleAnalyzer 使用 LetterTokenizer,仅返回字母。
考虑使用 KeywordAnalyzer 代替
id
字段。SimpleAnalyzer uses LetterTokenizer, which only returns letters.
Consider using the KeywordAnalyzer instead for the
id
field.