Hi Travis

That's some pretty complicated code there, so maybe I'm jumping ahead a little 
too far... but, if you want to limit results to anything within a 10 mile 
radius, that's easy enough. All you need to do is add a range filter on 
@geodist:

Banner.search @terms,
  :geo   => [[email protected], @zip.longitude],
  :with  => {'@geodist' => 0.0..10_000.0},
  :order => '@geodist ASC'

However, Sphinx uses metric, and so you'll need to convert 10 miles to metres - 
roughly 16km, so try the following instead:

Banner.search @terms,
  :geo   => [[email protected], @zip.longitude],
  :with  => {'@geodist' => 0.0..16_000.0},
  :order => '@geodist ASC'

Hope this helps :)

-- 
Pat

On 30/12/2009, at 5:25 PM, Travis wrote:

> Hi Guys,
> 
> I am new to this group and to the Thinking Sphinx rails plugin and
> Sphinx search dameon. I am up and running and with Thinking Sphinx in
> my application and it's truly amazing!  So here is my question, my
> application has many tables that store latitude and longitude
> information about each item and will return items based on a radius
> search, i.e., items that are with x miles between lat and long
> points.  Currently I am doing this both in the models and controllers
> (messy, but works) using find_by_sql calls and using sql such as this,
> for example this controller call for all banners within 10 miles of a
> set of lat and longs.
> 
> @rsbanners = Banner.find_by_sql ["SELECT * FROM banners
>     WHERE (3958*3.1415926*sqrt((bannerlatitude-'#[email protected]}')*
> (bannerlatitude-'#[email protected]}')
>     + cos(bannerlatitude/57.29578)*cos('#[email protected]}'/57.29578)*
> (bannerlongitude-'#[email protected]}')*(bannerlongitude-'#
> {[email protected]}'))/180)
>     <= 10 AND banneractive = '1'"]
> 
> I was able to build my index with lats and longs from the example
> documentation and do a basic search against the index for all banners
> and sorting by distance.  The geo functionality is fantastic and works
> great:
> @banners = Banners.search @terms, :geo => [[email protected],
> @zip.longitude],:order => "@geodist DESC
> 
> Can anyone give me some advice on how to go about converting my
> example find_by_sql statement above to using the Thinking Sphinx
> plugin?  Can it be done?
> 
> Many thanks for your help!  And a huge thanks to Pat Allen for
> creating such a fantastic search platform to work with!
> 
> --Travis
> 
> --
> 
> 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.
> 
> 

--

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.


Reply via email to