Sort result by date difference

匆匆过客 提交于 2019-12-22 12:23:49

问题


We have a solr result queried by a date range +/- 1 Month of the date entered. If i entered 2012-12-01 i get a Result Set from 2012-11-01 to 2013-01-01.

This works fine, but we want to sort the Result after the date difference to the date entered.

For example if we have the Dates:

2012-11-10, 2012-11-30, 2012-12-03, 2012-12-10

we want the Result sorted like this:

2012-11-30, 2012-12-03, 2012-12-10, 2012-11-10

Any Ideas how to accomplish this in solr?

Thanks in advance!


回答1:


you can just add &sort=sub(date_you_enter,date_fieldname_on_documents) asc parameter to your query. basically sub function will calculate the difference and then you will be able to sort it depending on that result.

for reference you can also check http://wiki.apache.org/solr/FunctionQuery page for more functions that could be useful for you



来源:https://stackoverflow.com/questions/13366620/sort-result-by-date-difference

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