Hi Nickolay

There's no single-command request that'll do what you need,  
unfortunately. Sphinx's grouping functionality will return one event  
for each venue - so your approach is probably as good as it's going to  
get. You could also load each Venue, then make Sphinx queries for each  
one... pagination either way isn't going to be ideal though...

Cheers

-- 
Pat

On 27/01/2009, at 6:32 PM, Nickolay Kolev wrote:

>
> Hi all,
>
> I would like to use the grouping feature of Sphinx but can't seem to
> figure it out. I have two models like this:
>
> class Venue < AR::B
>  has_many :events
> end
>
> class Event < AR::B
>  belongs_to :venue
>
>  define_index do
>    indexes :name
>    indexes :description
>
>    has "radians(venues.lat)", :as => :lat, :type => :float
>    has "radians(venues.lng)", :as => :lng, :type => :float
>
>    has venue(:id), :as => :venue_id
>
>    set_property :latitude_attr   => "lat"
>    set_property :longitude_attr  => "lng"
>  end
> end
>
> I am searching for events and grouping them by venues. Right now this
> is done in Ruby like this:
>
> result = Event.search(
>  "query",
>  :geo => [origin_lat * Math::PI / 180, origin_lng * Math::PI / 180],
>  :with => { "@geodist" => 0.0..10000.0 },
>  :order => "@geodist asc",
>  :include => :venue
> )
> @venues = Hash.new { |h,k| h[k] = Array.new() }
> result.each_with_geodist do |event, distance|
>  venue = menu_item.venue
>  venue.dist = distance
>  @venues[venue] << event
> end
>
> In the view I show the venues sorted by their distance:
>
> @venues.keys.sort_by {|v| v.dist}.each do |venue|
> ...
> end
>
> This gives me a nice way to loop over all venues and show the
> associated events. I was wondering if I could skip the grouping in
> Ruby and use Sphinx grouping and ordering?
>
> Many thanks in advance!
>
> Best,
> Nickolay
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
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