这是ES中的数据模型:
{
id: 1,
dateRanges: [
{ from: 2014-01-01, to: 2014-01-05 },
{ from: 2014-01-08, to: 2014-01-10 },
...
]
}
现在我想根据当前日期对我的文档进行评分。伪代码:
SCORE =
if( today IS IN any dateRange ) {
return MAX_VALUE;
} else if( today < any dateRange.from ) {
dateRange.from = lowest dateRange.from, which is > today;
return 1 / ( dateRange.from - today );
} else {
dateRange.to = highest dateRange.to, which is < today;
return dateRange.to - today;
}
id | dateRange1 | dateRange2 | ...
-------------------------------------------------------------------
1 | 2014-01-01 to 2014-01-10 | 2014-01-12 to 2014-01-13 |
2 | 2014-01-03 to 2014-01-03 | |
3 | 2014-01-01 to 2014-01-02 | 2014-01-10 to 2014-01-15 |
today = 2014-01-11
结果应按此顺序排列:3 1 2
原因:
3
得分最高,因为today
至少在一个日期范围内1
获得第二高的得分,因为它至少有一个日期范围dateRange.from > today
2
得分最低,因为其所有日期范围均为dateRange.to < today
有谁知道怎么做?
感谢您的帮助:)