现在的位置: 首页 > 综合 > 正文

lucene 3.0与之前版本的一些区别导致的问题

2013年04月20日 ⁄ 综合 ⁄ 共 735字 ⁄ 字号 评论关闭

score为NAN

在文章http://bbs.chinaunix.net/viewthread.php?tid=1632554 中找到答案; 

Java代码  收藏代码
  1. IndexSearcher searcher = new IndexSearcher(dir,true);  
  2. //加上这句  
  3. searcher.setDefaultFieldSortScoring(truefalse);  



解释如下: 

Java代码  收藏代码
  1. public void setDefaultFieldSortScoring(boolean doTrackScores,  
  2.                                        boolean doMaxScore)  
  3. 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.  
  4.   
  5. Parameters:  
  6. doTrackScores - If true, then scores are returned for every matching document in TopFieldDocs.  
  7. doMaxScore - If true, then the max score for all matching docs is computed.  

抱歉!评论已关闭.