2
class Office < ActiveRecord::Base
has_many :users
searchable do
text :name
location :coordinates do
Sunspot::Util::Coordinates.new(latitude, longitude)
end
end
end
class User < ActiveRecord::Base
belongs_to :office
searchable do
text :name, :default_boost => 2
text :description
end
end
使用這種設置,我如何在給定經緯度的用戶的Rails上使用SunSpot(在Solr上)進行搜索?舉例來說,我希望能夠做到這一點:SunSpot通過關聯尋找地址
@search = User.search() do
fulltext(params[:q])
with(:coordinates).near(@lat, @long, :precision => 5)
end
下面的作品就好了:
@search = Office.search() do
fulltext(params[:q])
with(:coordinates).near(@lat, @long, :precision => 5)
end
什麼是實現這一目標的最佳途徑鑑於經/緯每個用戶真正生活在辦公室課?