免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 7849 | 回复: 8
打印 上一主题 下一主题

lucene中的评分问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-22 16:34 |只看该作者 |倒序浏览
用lucene中的IndexSearcher查询,用默认的相关度计算器,搜索到的文档的score值全为NAN是怎么回事?用IndexSearcher.explain(q, docid)解释一下是这样的


this document's score is NaN
0.71933484 = (MATCH) sum of:
  0.4066309 = (MATCH) weight(content:甲 in 7), product of:
    0.6658104 = queryWeight(content:甲), product of:
      3.454815 = idf(docFreq=401, maxDocs=4681)
      0.19271956 = queryNorm
    0.61073077 = (MATCH) fieldWeight(content:甲 in 7), product of:
      2.828427 = tf(termFreq(content:甲)=
      3.454815 = idf(docFreq=401, maxDocs=4681)
      0.0625 = fieldNorm(field=content, doc=7)
  0.3127039 = (MATCH) weight(content:流 in 7), product of:
    0.746121 = queryWeight(content:流), product of:
      3.8715372 = idf(docFreq=264, maxDocs=4681)
      0.19271956 = queryNorm
    0.4191062 = (MATCH) fieldWeight(content:流 in 7), product of:
      1.7320508 = tf(termFreq(content:流)=3)
      3.8715372 = idf(docFreq=264, maxDocs=4681)
      0.0625 = fieldNorm(field=content, doc=7)

这是其中一个文档的结果,输出结果中最大score也是NaN,不知道出现这种情况一般是因为什么原因。我用的lucene的2.9.1版本。
谢谢大家了

论坛徽章:
0
2 [报告]
发表于 2009-12-24 10:41 |只看该作者
你索引什么版本创建的?

按照你列出信息,,score应该是0.71933484

现在3.0也出了。

论坛徽章:
0
3 [报告]
发表于 2009-12-25 14:01 |只看该作者

回复 #2 james.liu 的帖子

上面哪个是2.9.1版本的,现在换成3.0试了一下,也是NaN,这个是新的结果


Document<stored,indexed,tokenized<myTITLE:甲流病因分析> stored,indexed,tokenized<myCONTENT:随着天气越来越冷,甲型H1N1流感不仅继续蔓延,而且在北半球进入了第二次高峰,感染人数和死亡病例激增。尽管如此,很多人对甲流仍存在不少认识上的误区,对甲流病因的分析>>
NaN
0.47855338 = (MATCH) sum of:
  0.35355338 = (MATCH) weight(myTITLE:甲流 in 1), product of:
    0.70710677 = queryWeight(myTITLE:甲流), product of:
      1.0 = idf(docFreq=1, maxDocs=2)
      0.70710677 = queryNorm
    0.5 = (MATCH) fieldWeight(myTITLE:甲流 in 1), product of:
      1.0 = tf(termFreq(myTITLE:甲流)=1)
      1.0 = idf(docFreq=1, maxDocs=2)
      0.5 = fieldNorm(field=myTITLE, doc=1)
  0.12499999 = (MATCH) weight(myCONTENT:甲流 in 1), product of:
    0.70710677 = queryWeight(myCONTENT:甲流), product of:
      1.0 = idf(docFreq=1, maxDocs=2)

论坛徽章:
0
4 [报告]
发表于 2009-12-25 14:07 |只看该作者
原帖由 james.liu 于 2009-12-24 10:41 发表
你索引什么版本创建的?

按照你列出信息,,score应该是0.71933484

现在3.0也出了。



既然是有计算出来的值,为什么我直接输出这个值的时候会输出NaN呢?
我用来检索的语句是这样的

                    IndexSearcher searcher = new IndexSearcher(dir,true);
                  
                    
                    String query = "甲流";
                    String fields[] = {"myTITLE" , "myCONTENT"};
                    Query q = IKQueryParser.parseMultiField(fields, query);
                  
                    TopDocs results = searcher.search(q , null , 100 , Sort.RELEVANCE);
                    ScoreDoc[] sdocs = results.scoreDocs;
                    
                    for(int i =0; i< sdocs.length; i++){
                            System.out.println(searcher.getIndexReader().document(sdocs.doc));
                            System.out.println(sdocs.score);
                            System.out.println(searcher.explain(q, sdocs.doc));
                    }

论坛徽章:
0
5 [报告]
发表于 2009-12-29 16:14 |只看该作者

  1. Explanation explanation = searcher.explain(q, sdocs.doc);

  2. System.out.println(explanation.toString());
复制代码

把它放入循环

其他输出暂时注释掉

论坛徽章:
0
6 [报告]
发表于 2010-02-25 18:26 |只看该作者
本帖最后由 refactor 于 2010-02-25 18:35 编辑

Lucene在2.9版后
把 TopDocs results = searcher.search(q , null , 100 , Sort.RELEVANCE);
改成
  1.         TopFieldCollector tfc = TopFieldCollector.create(Sort.RELEVANCE, 100,
  2.                 false /* fillFields */,
  3.                 true /* trackDocScores */,
  4.                 true /* trackMaxScore */,
  5.                 false /* docsInOrder */);
  6.         searcher.search(query, tfc);
  7.         TopDocs results = tfc.topDocs();
复制代码
就能得到score值了

论坛徽章:
0
7 [报告]
发表于 2010-02-26 01:41 |只看该作者
本帖最后由 refactor 于 2010-02-26 01:48 编辑

最简单的办法,加上这句
  1. IndexSearcher searcher = new IndexSearcher(dir,true);
  2. 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.

论坛徽章:
0
8 [报告]
发表于 2010-04-26 20:09 |只看该作者
学习了

论坛徽章:
0
9 [报告]
发表于 2012-03-31 16:21 |只看该作者
木兰豆豆 发表于 2009-12-25 14:07
既然是有计算出来的值,为什么我直接输出这个值的时候会输出NaN呢?
我用来检索的语句是这样的
:wink:
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP