新手问题 sunspot 如何根据经纬度计算出来的距离排序?

lup165340815 · January 05, 2015 · 1680 hits

#encoding: utf-8

== Schema Information

#

Table name: users

......

lng :float

lat :float

#

Indexes

#

index_users_on_kael_user_id (kael_user_id)

index_users_on_mobilephone (mobilephone) UNIQUE

# class User < ActiveRecord::Base has_secure_password

......

searchable do float :lat float :lng latlon :location end end

lat, lng = @current_user.lat, @current_user.lng result = User.search do order_by_geodist(:location, lat, lng, :desc) end

user 中有经纬度 lat 和 png, 返回的 result 结构为Sunspot::Search::fq={["type:User"], :sort=>"geodist(location_ll,34.2336,142.366) desc", :start=>0, :rows=>30, :q=>":"}>,获取 result.hits 则为空 []。求大神指点~~

No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.