@professional_services =
Professional::Service.search @keywords, where: {
location: {
near: { lat: @cordinate[0], lon: @cordinate[1] },
within: "100km"
}
}
如何按距离搜索此搜索?
答案 0 :(得分:1)
如果您只是想按距离排序,可以使用以下代码段
@professional_services =
Professional::Service.search @keywords, order: {
_geo_distance: {
location: "#{@cordinate[0]}, #{@cordinate[1]}",
order: "asc"
}
}
答案 1 :(得分:0)
我按查询距离对结果进行排序:
@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"}
}]