简体   繁体   English

Apache Solr按功能排序

[英]Apache Solr sort by function

Trying to sort a query by a field closest to today. 尝试按最接近今天的字段对查询进行排序。 From what i understand the sub function only allows references to the document. 据我了解,子功能仅允许引用文档。 Is it possible to perform this via other means? 是否可以通过其他方式执行此操作?

This is the error returned by Solr: sort param could not be parsed as a query, and is not a field that exists in the index: sub(NOW,StartDate)','code'=>400}} 这是Solr返回的错误:无法将sort参数解析为查询,并且不是索引中存在的字段:sub(NOW,StartDate)','code'=> 400}}

eg sort=sub(NOW, StartDate) asc 例如sort = sub(NOW,StartDate)asc

Use the ms function if you're planning to do arithmetic operations on dates. 如果您打算对日期进行算术运算,请使用ms函数。 This will convert the date to an integer. 这会将日期转换为整数。

In fact, the examples for ms shows exactly what you're trying to do: 实际上, ms的示例准确显示了您要执行的操作:

ms(NOW,mydatefield)

.. which is described as ..被描述为

ms(a,b) : Returns the number of milliseconds that b occurs before a (that is, a - b) ms(a,b):返回b在a之前发生的毫秒数(即a-b)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM