在Solr FunctionQuery中支持三元运算符

时间:2014-02-06 22:21:04

标签: solr solrj

我正在尝试运行solr搜索,我需要对字段组合进行排序,例如

q=*:*&sort=endtime != null ? endtime : starttime - 100;

据我所知,Solr文档(http://wiki.apache.org/solr/FunctionQuery)不支持。还有其他方法可以实现吗?

1 个答案:

答案 0 :(得分:1)

您需要在sortMissingLast的架构中使用endtime

来自http://lucene.472066.n3.nabble.com/about-sortMissingLast-and-sortMissingFirst-td473881.html - if sortMissingLast=true then it doesn't matter whether you sort "asc" or "desc", documents that don't have a value for that field will always come last. if sortMissingLast="false" then the default Lucene sort behavior is used, in which "missing" values are sorted the same as empty strings -- it is the "lowest" possible value, so they come first in asc sorts.

完成后,您可以发出以下查询: q=*:*&sort=endtime desc,starttime desc

(我不确定为什么你需要从starttime中减去100,因为排序顺序是相同的。)

相关问题