Hi Pat, et al,
I am using Thinking Sphinx for a geo search of a large location
database with multiple assocs.
I am storing my lat/lngs as decimals in a postgres database. All of
this stuff works nicely with GeoKit.
Anyway, I really like the way TS searches and now that I have the geo
stuff (sort of ) working I wanted to post a message about some
interesting things I am seeing...
First, when I convert from the floating point val from postgres to
radians using the simple mixin:
class Numeric
def to_radians
( self / 360.0 ) * Math::PI * 2
end
end
and add it to my search like such:
@records = Location.search(@search_terms,
#:geo => [...@geo_location[:lat].to_f.to_radians,
@geo_location[:lng].to_f.to_radians ],
I get records way off. I am in mission viejo and the location records
that are coming back are in LA...
However, when I remove the .to_radians and just pass in the floating
point value for the lat/lng I get stuff very nearby...
WIERD?
So I am just not sure what is going on as the documentation says to
convert lat/lng to radian.
The distance is also way off... I know it is in meters so I am
converting it to miles using alchemist:
organic_map_popup.sphinx_attributes['@geodist'].meters.to.miles
but it is still coming up 300 miles off!!
my query looks something like this:
@distance_in_miles_to_search = 300.miles.to.meters.value.to_f
@records = Location.search(@search_terms,
#:geo => [...@geo_location[:lat].to_f.to_radians,
@geo_location[:lng].to_f.to_radians ],
:geo => [...@geo_location[:lat].to_f, @geo_location[:lng].to_f ],
:order => "@geodist ASC, @relevance DESC",
:include => [:business, :address],
:field_weights => {
:tags => 9,
:name => 10,
:category => 8 },
:with => {"@geodist" => 0....@distance_in_miles_to_search})
If I change that to 30 miles it comes up with nothing...
here is the define index on the searchable model:
define_index do
indexes business.name
indexes tags.name, :as => :tags
indexes business.categories.name
has address.lat, address.lng
has "RADIANS(addresses.lat)", :as => :latitude, :type => :float
has "RADIANS(addresses.lng)", :as => :longitude, :type => :float
end
Anyway, I love thinking sphinx, but I just have never been able to use
it correctly with geo searching...
I am using:
rails 2.3.8
ruby 1.8.7 (ubuntu linux)
thinking-sphinx (1.3.18)
sphinx-0.9.9
Any help would be totally appreciated!
All the best,
Mark McDonald
--
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.