Thank you, Jim. :with => {"@geodist" => 0.0..500.0} instead
of :conditions made filtering work.
But there is still that exception if I try to use each_with_geodist
function:
undefined method `each_with_geodist' for #<WillPaginate::Collection:
0x7fdffaca52d8>
I use :order => "@geodist ASC" parameter in search call. And sorting
actually works! But there's no way to get to 'each_with_geodist'
function to retrieve distances from Sphinx. Currently I calculate
these distances in ruby. But that's not the wright way to do it.
Maybe there's some another trick that can make it work?
My current code looks like this:
@location = Location.find @search.location_id
lat, lon = @location.lat * Math::PI/180, @location.lon * Math::PI/
180
@ads = Ad.search(
@search.query,
:conditions => @search.conditions,
:per_page => @search.per_page, :page => params[:page],
:geo => [lat, lon],
:order => "@geodist ASC",
:include => {:subcategory => :category},
:with => {"@geodist" => [email protected]_distance_in_meters}
)
#...@dist = {}
#[email protected]_with_geodist do |ad, dist|
#...@dist[ad.id] = dist
#end
@distances = {}
@ads.each do |ad|
@distances[ad.id] = @search.distance_from_to @location,
ad.location
end
Thanks.
Anton
On 13 Бер, 18:54, Jim Griswold <[email protected]> wrote:
> I'm on sphinx 0.9.8.1 (r1533), TS 0.9.5, and I had similar
> frustrations.
>
> It should work if you do :with => {"@geodist" =>
> -1000000000000000000000.0..20000000000000.0} as opposed to :conditions
> => ...
>
> Also, interestingly, each_with_geodist doesn't seem to yield with a
> distance unless you filter on or order by @geodist. I'm guessing
> that's what you'll be doing in almost every case, but perhaps worth
> knowing.
>
> Hope that helps.
>
> Jim
>
> On Mar 12, 1:15 pm, AST <[email protected]> wrote:
>
> > Hi, I'm trying to use geo facilities of Sphinx. And am having two
> > issues with it.
>
> > First, regular search (Model.search ...) works smoothly. No problems.
>
> > But when I try to make use of geo sorting or geo filtering, I see
> > these:
>
> > 1. No way to get distances for each Ad. There is no such function as
> > @ads.each_with_geodist, which is mentioned in the documentation.
>
> > 2. If I try to add filtering by @geodist attribute (... :conditions
> > => {"@geodist" => -1000000000000000000000.0..20000000000000.0} ...) I
> > get empty collection as a result.
>
> > Details:
> > Model
>
> > class Ad < ActiveRecord::Base
> > define_index do
> > indexes title
> > indexes description
> > has 'RADIANS(lat)', :as => :lat, :type => :float
> > has 'RADIANS(lon)', :as => :lon, :type => :float
> > set_property :latitude_attr => 'lat'
> > set_property :longitude_attr => 'lon'
> > end
> > end
>
> > Use
>
> > @ads = Ad.search params[:query], :geo => [params
> > [:lat].to_f*Math::PI/180, params[:lon].to_f*Math::PI/180], \
> > :per_page => 50, :order => "@geodist ASC"
>
> > I've tried to run this code with different version of Sphinx(0.9.8.1,
> > 0.9.9-rc1) and ThinkingSphinx(0.9.5, edge), but still no luck.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---