How can I sort solr result bases on dynamic fields

假如想象 提交于 2019-12-01 10:32:51

问题


Thanks for giving your time.

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 .

could you help me , How can I sort for this type of dynamic field.


回答1:


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

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

//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))

Extract of solr def doc

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

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

See reference solr documentation



来源:https://stackoverflow.com/questions/36057394/how-can-i-sort-solr-result-bases-on-dynamic-fields

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