score为NAN
在文章http://bbs.chinaunix.net/viewthread.php?tid=1632554 中找到答案;
- IndexSearcher searcher = new IndexSearcher(dir,true);
- //加上这句
- searcher.setDefaultFieldSortScoring(true, false);
解释如下:
- public void setDefaultFieldSortScoring(boolean doTrackScores,
- boolean doMaxScore)
- By default, no scores are computed when sorting by field (using Searcher.search(Query,Filter,int,Sort)). You can change that, per IndexSearcher instance, by calling this method. Note that this will incur a CPU cost.
- Parameters:
- doTrackScores - If true, then scores are returned for every matching document in TopFieldDocs.
- doMaxScore - If true, then the max score for all matching docs is computed.