I would recommend trying to get it work first with Radians (as that's  
what Ultrapshinx expects). If that works then switch to degrees and  
make sure you set the config variable.


http://blog.evanweaver.com/files/doc/fauna/ultrasphinx/classes/Ultrasphinx/Search.html
Geographic distance
If you pass a :location Hash, distance from the location in meters  
will be available in your result records via the distance accessor:
@search = Ultrasphinx::Search.new(:class_names => 'Point', :query =>  
'pizza', :sort_mode => 'extended', :sort_by => 'distance', :location  
=> { :lat => 40.3, :long => -73.6 })
@search.run.first.distance #=> 1402.4
Note that Sphinx expects lat/long to be indexed as radians. If you  
have degrees in your database, do the conversion in the is_indexed as  
so:

is_indexed 'fields' => [ 'name', 'description', {:field =>  
'lat', :function_sql => "RADIANS(?)"}, {:field => 'lng', :function_sql  
=> "RADIANS(?)"} ]
Then, set Ultrasphinx::Search.client_options[:location][:units] =  
‘degrees‘.

The MySQL :double column type is recommended for storing location  
data. For Postgres, use <tt>:float</tt



Ryan



On May 28, 2008, at 1:50 AM, vikki wrote:


Hi all,

I'm trying to use geo-location based search using sphinx, Here my
search query.

@search = Ultrasphinx::Search.new(:sort_mode => 'extended', :sort_by
=> 'distance', :location => {:units => 'degrees', :lat =>
40.7414, :long => -74.0014})
@search.results.collect{|x| x.distance}
[0.69084495306015, 400.852783203125, 8684957.0]


But when using :query option with location search, it returns distance
as NaN

@search = Ultrasphinx::Search.new(:query=>"sr.software",:sort_mode =>
'extended', :sort_by => 'distance', :location => {:units =>
'degrees', :lat => 40.7414, :long => -74.0014})
@search.results.collect{|x| x.distance}
[NaN, NaN, NaN]

Please suggest one good solution to use both :query and :location


Regards,
T.Veeraa.



--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---

Reply via email to