How to sort by date in SOLR?

南笙酒味 提交于 2019-12-19 13:29:57

问题


I want to sort the results and scores returning from SOLR search,how I can get scores based on date like below:

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

My solr date filed lis like below:

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

I checked this docs but couldn't find that.

Thanks.


回答1:


You can pass the sort parameter in the URL

e.g. sort=published_date desc for documents by published date in descending order.

If you want to sort by score and date you can use sort=score desc, published_date desc




回答2:


taken from 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. 

combine that with this and the job is done :) it's pretty easy, it just requires some tries in the beginning

a little edit: this method allows you to retrieve values based on a date range and apply a score boost to them according to their values. apparently you were asking help on how to retrieve sort on base score and date, so my answer isn't the 100% correct one



来源:https://stackoverflow.com/questions/12970666/how-to-sort-by-date-in-solr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!