[英]How order searchkick search by distance?
@professional_services =
Professional::Service.search @keywords, where: {
location: {
near: { lat: @cordinate[0], lon: @cordinate[1] },
within: "100km"
}
}
如何按距离排序此搜索?
如果您只想按距离排序,可以使用下面的代码片段
@professional_services =
Professional::Service.search @keywords, order: {
_geo_distance: {
location: "#{@cordinate[0]}, #{@cordinate[1]}",
order: "asc"
}
}
我用查询按距离对结果进行排序:
@professional_services =
Professional::Service.search "*", where: {
location: {
near: {lat: @cordinate[0], lon: @cordinate[1]}, within: "10000km"
}
},
order: [{
_score: :desc}, {_geo_distance: {location: "#{@cordinate[0]},
#{@cordinate[1]}", order: "asc",unit: "km"}
}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.