简体   繁体   English

如何通过距离顺序搜索搜索?

[英]How order searchkick search by distance?

@professional_services = 
  Professional::Service.search @keywords, where: {
    location: { 
      near: { lat: @cordinate[0], lon: @cordinate[1] }, 
      within: "100km"
    }
  }  

How order this search by distance? 如何按距离排序此搜索?

If you just want to sort by distance can use below code snippet 如果您只想按距离排序,可以使用下面的代码片段

@professional_services =  
Professional::Service.search @keywords, order: {
    _geo_distance: {
        location: "#{@cordinate[0]}, #{@cordinate[1]}",
        order: "asc"
    }
}

I sort results by distance with the query: 我用查询按距离对结果进行排序:

@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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM