Here is the index:
define_index do
indexes name, :sortable=>:true
indexes zip
has zip_code.lat #need this or ts won't add the join for the
zip_codes table. hopefully this will be fixed in a new version of ts
has "RADIANS(zip_codes.lat)", :as => :latitude, :type => :float
has "RADIANS(zip_codes.lng)", :as => :longitude, :type => :float
set_property :delta => :datetime, :threshold => 10.minutes
set_property :enable_star => true
set_property :morphology => 'none'
end
Here is the truncated data from the sphinx query:
id name zip lat latitude longitude
3 steve 32257 30.1893550000 0.526903643803413 -1.42440622491863
4 allan 91711 34.1274400000 0.595636193276814 -2.0545192857202
Here is the ts query:
Model.search :per_page=>25, :enable_star=>true, :geo=>[0.5956361925962,
-2.05451928337257], :min_prefix_len=>0, :order=>"@geodist ASC,
@relevance DESC", :page=>1, :min_infix_len=>1
Here are the results:
[#<Model id: 3, name: "steve">, #<Model id: 4, name: "allan">]
Here is the geodist:
results.map{|x| x.sphinx_attributes['@geodist']}
[11989305.0, 13507781.0]
Am I crazy?
1. Shouldn't the results be in order [4,3]?
2. Shouldn't the map of geodist be more like [close to zero, really
big number]?
I had a similar problem. Try adding the following to your query:
:latitude_attr => :latitude, :longitude_attr => :longitude
These tell Thinking Sphinx which attributes to use for geodist, since
you have both lat and latitude.
-T-
> --
> 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.
>
As Timo's suggested, the issue is that you've got two attributes for latitude, and TS defaults to lat first. Instead of using zip_code.lat, you could use zip_code.id instead:
has zip_code.id, :as => :zip_id
Or, if you update to 1.3.18 or later (1.4.10 is the latest for Rails 2.x), you can just use the join method instead:
join zip_code
Cheers
--
Pat