Hi Greg
I'm not sure if it'll make a difference, but it's probably a good idea
to make sure both end points of your range are floats:
0.0..500.0
Beyond that, I'm not spotting anything immediately obvious with your
code. Just to confirm the problem - you're getting some results back,
but only those at the exact co-ordinates that you're sending through
as part of the search?
--
Pat
On 09/09/2009, at 5:28 AM, Greg Moreno wrote:
>
> Hello,
>
> I would like to return all records within 1 km radius from a given
> point but is not giving the results I expected. What happens is given
> a [lat, lng], only the records with the given coordinates are returned
> even though I've set the @geodist (i.e., :with => {"@geodist" =>
> 0.0..500},) . Below are my models and search code.
>
> Just to test, I use acts_as_mappable's find and it gives the
> expected results:
>>> Location.find(:all, :origin => near.address, :within =>
>>> 0.5).collect(&:locatable).paginate(:page => params[:page])
>
>
> class Workspace < ActiveRecord::Base
> has_one :location, :as => :locatable, :dependent => :destroy
>
> define_index do
> indexes location.city.name, :as => :city
>
> has location(:id), :as => :location_id
> has 'RADIANS(locations.lat)', :as => :lat, :type => :float
> has 'RADIANS(locations.lng)', :as => :lng, :type => :float
> set_property :latitude_attr => 'lat'
> set_property :longitude_attr => 'lng'
>
> set_property :delta => true
> end
> end
>
> class Location < ActiveRecord::Base
> acts_as_mappable :auto_geocode => true
>
> belongs_to :locatable, :polymorphic => true
> belongs_to :city
>
> validates_presence_of :lat, :lng
> end
>
>
> def search_locatables
> options = { :page => (params[:page] or 1), :per_page => PER_PAGE }
>
> near = Location.find(params[:near])
> lat = (near.lat / 180.0) * Math::PI
> lng = (near.lng / 180.0) * Math::PI
>
> options.merge! :geo => [lat, lng], :with => {"@geodist" =>
> 0.0..500},
> :latitude_attr => :lat, :longitude_attr => :lng
>
> if City.current
> options.merge! :conditions => {:city => City.current.name}
> end
>
> ThinkingSphinx.search params[:q], options
> end
>
>
> Best regards,
>
> Greg
>
> --
> Starting From Scratch
> http://gregmoreno.ca
>
> I'm on Twitter too!
> http://twitter.com/gregmoreno
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---