First thing to note is that Sphinx doesn't handle any more than one lat/lng pair for a document... so, it sounds like the index is best placed on the UserTagSubscription object (has_one location, so still one set). Given the tag is attached to that model as well, it should be pretty simple:
define_index do
indexes tag.name, :as => :tag
has tag_id, user_id
has location.lat, :as => :lat
has location.lng, :as => :lng
end
UserTagSubscription.search(
:with => {:tag_id => tag.id, '@geodist' => 0..100000},
:geo => [lat, lng]
).collect &:user_id
If you're using Sphinx 2.0.x and the latest Thinking Sphinx, then you may even be able to get the user email addresses without needing to instantiate user objects:
has user.email, :as => :email
UserTagSubscription.search(
:with => {:tag_id => tag.id, '@geodist' => 0..100000},
:geo => [lat, lng]
).collect { |uts| uts.sphinx_attributes['email'] }
That's untested, though... it's theoretically possible, though.
--
Pat
> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To post to this group, send email to thinkin...@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
>