@professional_services =
Professional::Service.search @keywords, where: {
location: {
near: { lat: @cordinate[0], lon: @cordinate[1] },
within: "100km"
}
}
如何按距离排序此搜索?
最佳答案
我用查询按距离对结果进行排序:
@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"}
}]
关于ruby-on-rails - 如何通过距离顺序搜索搜索?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47637097/