Lucene .NET not returning search results

天涯浪子 提交于 2019-12-07 22:49:50

问题


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)


回答1:


SimpleAnalyzer uses LetterTokenizer, which only returns letters.

Consider using the KeywordAnalyzer instead for the id field.



来源:https://stackoverflow.com/questions/6538446/lucene-net-not-returning-search-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!