I am using an example here to show the problem.  As far as I can tell,
either I am doing something wrong, or geodist search doesn't work
right with multiple locations.

Here is the example:
User model and a Location model.  A User has many Locations.
Locations is actually a polymorphic model, as other objects may have
locations as well - I don't think this affects the results.

USERS TABLE
| id | login |
| 1 | User_1 |
| 2 | User_2 |
| 3 | User_3 |

LOCATIONS TABLE
| id | user_id | location | latitude | longitude
| 1 | 1 | New York, NY | -73.986951 | 40.756054
| 2 | 2 | Pittsburgh, PA | -80.001933 | 40.438423
| 3 | 3 | Los Angeles, CA | -118.243425 | 34.052187
| 3 | 3 | Philadelphia, PA | -75.163808 | 39.951639

In the User model...
  define_index do
    indexes login
    has 'RADIANS(locations.latitude)', :as => :latitude,  :type
=> :float
    has 'RADIANS(locations.longitude)', :as => :longitude,  :type
=> :float
    set_property :latitude_attr   => "latitude"
    set_property :longitude_attr  => "longitude"
    set_property :delta => true
  end


Here is a search to find users closest to New York, NY.

The search query:
results=User.search :geo => [-73.986951 * Math::PI / 180, 40.756054 *
Math::PI / 180], :order => "@geodist asc"

Parsing through results..

results.each_with_geodist do |result, distance|
puts result.login + " is " + (distance / 1609.344).to_i.to_s + " miles
away from New York, NY"
end

Here is the output:
User_1 is 0 miles away from New York, NY
User_2 is 416 miles away from New York, NY
User_3 is 3058 miles away from New York, NY

The results seem to consider only the first location record of each
user.  User_3 is actually closer to New York than User_2 because of
the Philadelphia location, but this location is not reflected in the
results.

Any idea what I am doing wrong here?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to