[英]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.