如何在SOLR中按日期排序?

时间:2012-10-19 08:53:44

标签: search solr

我想对从SOLR搜索返回的结果和分数进行排序,如何根据以下日期获得分数:

Suppose for keywords "football"
  12-10-2012 - 3.2
  13-10-2012 - 1.5

我的solr日期提交如下:

  <field name="published_date" datetimeformat="dd-MM-yyyy"  type="date" indexed="true" stored="true"/>

我检查了这个docs,但找不到。

感谢。

2 个答案:

答案 0 :(得分:31)

您可以在网址

中传递sort参数

e.g。 sort=published_date desc按发布日期降序排列的文档。

如果您想按分数和日期排序,可以使用sort=score desc, published_date desc

答案 1 :(得分:1)

取自the wiki

Although not technically a Syntax difference, please note that if you use 
the Solr "DateField" type, any queries on those fields (typically range queries) 
should use either the Complete ISO 8601 Date syntax that field supports, 
or the DateMath Syntax to get
relative dates. Examples:

timestamp:[* TO NOW]

createdate:[1976-03-06T23:59:59.999Z TO *]

createdate:[1995-12-31T23:59:59.999Z TO 2007-03-06T00:00:00Z]

pubdate:[NOW-1YEAR/DAY TO NOW/DAY+1DAY]

createdate:[1976-03-06T23:59:59.999Z TO 1976-03-06T23:59:59.999Z+1YEAR]

createdate:[1976-03-06T23:59:59.999Z/YEAR TO 1976-03-06T23:59:59.999Z] 

NOTE:TO must be uppercase, or Solr will report a 'Range Goop' error. 

将其与this结合起来并完成工作:)这很简单,只需要在开始时进行一些尝试

稍加编辑:此方法允许您根据日期范围检索值,并根据其值对其应用分数提升。显然你在如何检索基本分数和日期的排序上寻求帮助,所以我的答案不是100%正确的