The Setup
The requested behaviour
Basically, the following rules have to apply for a post to be displayed:
post.radius >= distance(post, viewer)
viewer.radius >= distance(post, viewer)
The problem
The first rule is not too difficult to implement:
class Post < ActiveRecord::Base
searchable do
integer :radius
latlon(:location) { Sunspot::Util::Coordinates.new(latitude, longitude) }
end
end
# PostsController
Post.search do
with(:location).in_radius(viewer.latitude, viewer.longitude, viewer.radius)
end
The second rule, however, would require that I am able to utilize the distance between the post and the viewer inside the solr query, e.g. with
with(:radius).greater_than distance(:location, viewer.latitude, viewer.longitude)
---
As far as I see it, there is no way to achieve this with sunspot's built in methods.
Is solr even capable of handling queries like this?
If not, what might be a better solution to handle this problem?
Thanks in advance for any help (even it it's just a "Solr can't do that, sorry")!