如何根据动态字段对 solr 结果进行排序 [英] How can I sort solr result bases on dynamic fields

查看:33
本文介绍了如何根据动态字段对 solr 结果进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据动态字段对结果进行排序.我怎样才能做到这一点?当我对其中一些动态属性的最小值进行排序时.它没有给出正确的结果,因为我的查询就像 &sort=min(A_160018,A_chandigarh1) 一些文档同时具有 A_160018A_chandigarh1而有些文档没有字段,有些文档有 A_160018A_chandigarh1 用于某些结果文档.

I need to sort result on the basis of dynamic field. How can I do that? When I am sorting on minimum value of some of those dynamic attribute. It's not giving correct result because my query is like &sort=min(A_160018,A_chandigarh1) Some of document having both field A_160018 and A_chandigarh1 while some document having no field and some having one either A_160018 or A_chandigarh1 for some result doc.

如何对此类动态字段进行排序?

How can I sort for this type of dynamic field?

推荐答案

如果你不知道该字段是否存在,你可以设置一个默认值,以防它不存在.

If you do not know if the field exist, you can set a default value in case it does not exists.

尝试使用 def 函数,如果该字段不存在,它会返回一个默认值.

Try to use the def function, that returns a default vlaue if the field does not exist.

//在这部分查询中,我设置了一个非常高的默认值,以便将结果放在列表的底部&sort=min(def(A_160018,9000000),def(A_chandigarh1,9000000))

//in this part of query, I have put a default value that is very high in order to put the result on bottom of the list &sort=min(def(A_160018,9000000),def(A_chandigarh1,9000000))

solr def doc 摘录

Extract of solr def doc

def(field|function,defaultValue) 返回字段field"的值,或者如果该字段不存在,则返回指定的默认值.

def(field|function,defaultValue) returns the value of field "field", or if the field does not exist, returns the defaultValue specified.

示例使用: def(rating,5) def() 函数将在这里返回评分,或者如果文档中没有指定评分,则返回 5

Example use: def(rating,5) The def() function will here return the rating, or if no rating specified in the doc, returns 5

请参阅 参考 solr 文档

这篇关于如何根据动态字段对 solr 结果进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆