2014-04-13 29 views
0

我正在使用Lucene创建一个搜索引擎,它的一切进展顺利,但我不得不根据它们的相关性和年龄对结果进行评分和算法。我有三个输入:计算搜索结果的基于或相关性和年龄的评分

  • 相关性分数 - 的示例将是文件2.68065834
  • 年龄(在UNIX纪元格式 - 自1970年以来的秒例如数字) - 的例子是1380979800
  • 年龄scew(这是0到10之间,并且由用户指定,并允许他们控制文档的年龄怎样的影响很大,对整体分数)

我在做什么目前基本上是:

ageOfDocumentInHours = age/3600; //this is to avoid any overflows 
    ageModifier = ageOfDocumentInHours * ageScew + 1; // scew of 0 results in relevancy * 1 
    overallScore = relevancy * ageModifier; 

我对统计一无所知 - 有没有更好的方法来做到这一点?

感谢,

回答

0

这是我落得这样做:

public override float CustomScore(int doc, float subQueryScore, float valSrcScore) 
    { 
     float contentScore = subQueryScore; 

     double start = 1262307661d; //2010 

     if (_dateVsContentModifier == 0) 
     { 
      return base.CustomScore(doc, subQueryScore, valSrcScore); 
     } 

     long epoch = (long)(DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds; 
     long docSinceStartHours = (long)Math.Ceiling((valSrcScore - start)/3600); 
     long nowSinceStartHours = (long)Math.Ceiling((epoch - start)/3600); 

     float ratio = (float)docSinceStartHours/(float)nowSinceStartHours; // Get a fraction where a document that was created this hour has a value of 1 
     float ageScore = (ratio * _dateVsContentModifier) + 1; // We add 1 because we dont want the bit where we square it bellow to make the value smaller 

     float ageScoreAdjustedSoNewerIsBetter = 1; 

     if (_newerContentModifier > 0) 
     { 
      // Here we square it, multiuply it and then get the square root. This serves to make newer content have an exponentially higher score than old content instead of it just being linear 
      ageScoreAdjustedSoNewerIsBetter = (float)Math.Sqrt((ageScore * ageScore) * _newerContentModifier); 
     } 

     return ageScoreAdjustedSoNewerIsBetter * contentScore; 
    } 

的基本思路是,年龄得分是一个分数,其中0是在2010年的第一天, 1现在。然后这个十进制值乘以_dateVsContentModifier,它可以给日期增加一个相关性分数。

年龄scroe是平方,乘以_newerContentModifier然后平方根。这导致较新的内容比较旧的内容具有较高的分数。

Joe