I did the has and belongs to since what I was using before didn't seem to
work. I now changed it back to `belongs_to :locations`. Regardless with
your code the new error I get is…`undefined local variable or method
`latitude' for main:Object`
It's reading latitude instead of the form lat because I just renamed the
columns fyi.
BTW previously before I came here I was also trying this:
ThinkingSphinx::Index.define :user, :with => :active_record do
> # fields
> indexes name
> # attributes
> has created_at, updated_at
> has location.city, :as => :location_city
> has "RADIANS(locations.latitude)", :as => :latitude, :type => :float
> has "RADIANS(locations.longitude)", :as => :longitude, :type => :float
> end
With your assistance. This is how all my code looks now:
ThinkingSphinx::Index.define :location, :with => :active_record do
> indexes city
>
> has "RADIANS(locations.latitude)", :as => :latitude, :type => :float
> has "RADIANS(locations.longitude)", :as => :longitude, :type => :float
> end
> ThinkingSphinx::Index.define :user, :with => :active_record do
> indexes name, :as => :user, :sortable => true
> indexes religion, zip_code, about_me, career, sexuality, children,
> user_smoke, user_drink, gender, ethnicity, education
> has created_at, updated_at
> has locations.ids, :as => :locations_ids
> end
> location_ids = Location.search_for_ids :geo => [latitude, longitude],
> :with => {:geodist => 0.0..10_000.0}
> users = User.search ‘foo’, :with => {:location_ids => location_ids}
>
user.rb:
> belongs_to :location
> attr_accessible :name
location.rb:
> class Location < ActiveRecord::Base
> attr_accessible :city, :latitude, :longitude, :zipcode
> end
Distance controller:
> class DistanceController < ApplicationController
> def search
> @latitude = params[:latitude].to_f * Math::PI / 180
> @longitude = params[:longitude].to_f * Math::PI / 180
> @users = User.search :geo => [@latitude, @longitude], :with =>
> {:geodist => 0.0..200_000.0}, :order => "geodist ASC"
> end
> end
--
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/groups/opt_out.