如何设置Searchkick boost_by_distance?

时间:2015-08-30 05:46:19

标签: ruby elasticsearch mongoid searchkick

我尝试使用boost_by_distance来编写Searchkick的查询。但似乎最近的位置没有提升 而且我想找到距离城市30公里的任何地方,并且在20公里以上的地方也能提高成绩 但是,从城市地理位置非常接近地理定位的地方甚至没有回来测试。

main.rb

...  
city = City.search(params[:city], fields: [{city: :word_start}])
...     
@o = Organization.search("*",
        boost_by_distance: {field: :loc, origin: [city[0].try(:latitude).to_f, city[0].try(:longitude).to_f], function: :gauss, scale: "20km", decay: 0.5},
        where: {loc: {near: [city[0].try(:latitude).to_f, city[0].try(:longitude).to_f], within: "30km"}},
        page: params[:page], per_page: 20)
...  

organization.rb

class Organization
  include Mongoid::Document
  include Mongoid::Geospatial

  searchkick index_name: "organization",
             locations: ["loc"],
             word_start: ['base']

  def search_data
      attributes.merge loc: [latitude, longitude]
    {
      base: base,
      place: place
    }
  end

  field :base,     type: Srting
  field :place,     type: Srting
  field :latitude,     type: Float
  field :longitude,     type: Float
  field :location, type: Point, spatial: true

  index({ base: 1, place: 1, location: "2d" })

end

city.rb

class City
  include Mongoid::Document
  include Mongoid::Geospatial

  searchkick index_name: "city",
             word_start: ['city']

  def search_data
    {
      city: city,
    }
  end

  field :city,            type: String
  field :latitude,         type: Float
  field :longitude,         type: Float

end   

我尝试了很多方法来编写search_data,因为也许是自己的organization.rb search_data不正确。
我还在http://localhost:9200/_plugin/head/的浏览器中检查了字段FIELDS,但没有输入字段 请让我知道有什么问题或如何检查实际发送查询。

0 个答案:

没有答案