Hi Pat,
Thank you for replying so promptly, it's really appreciated.
As advised, I've added an index to the Site model, like so:
class Site < ActiveRecord::Base
acts_as_mappable
# associations
has_many :campaigns, :dependent => :destroy
has_many :promotions, :through => :campaigns
define_index do
indexes promotions.title, :as => :promotions_title
indexes promotions.details, :as => :promotions_details
has promotions(:id), :as => :promotions_ids
has 'RADIANS(sites.lat)', :as => :lat, :type => :float
has 'RADIANS(sites.lng)', :as => :lng, :type => :float
set_property :latitude_attr => "lat"
set_property :longitude_attr => "lng"
end
end
Then in my controller I do a Site.search 'widgets', :geo => [@lat,
@lng], :with => {"@geodist" => 0.0..10}
Now, here is where I get stuck. Sorry for the newb question....
That returns me an array of Sites. How do I get to the Promotions that
are associated with those sites in my views?
Thank you again for all your help.
Alex
On Jan 24, 1:51 pm, Pat Allan <[email protected]> wrote:
> Hi Alex
>
> Sphinx doesn't understand arrays of floats - so you can't have multiple
> lat/lng values for a single record.
>
> What you're going to need to do is have a search index for your Site model,
> and search upon that. You can use associations to pull in promotion titles
> and details, as well as adding a promotion id as an attribute.
>
> If you want, you could group your Site search results by promotion id, thus
> ensuring you don't get duplicate promotions (if that's what you'd prefer).
>
> Let me know if you get stuck.
>
> Cheers
>
> --
> Pat
>
> On 25/01/2011, at 12:35 AM, Alex wrote:
>
>
>
> > Hi,
>
> > I have models set up as follows:
>
> > class Promotion < ActiveRecord::Base
>
> > # associations
> > has_many :campaigns, :dependent => :destroy
> > has_many :sites, :through => :campaigns
>
> > define_index do
> > indexes :title
> > indexes :details
>
> > indexes sites.lat, :as => :site_lat
> > indexes sites.lng, :as => :site_lng
> > has 'RADIANS(sites.lat)', :as => :lat, :type => :float
> > has 'RADIANS(sites.lng)', :as => :lng, :type => :float
> > set_property :latitude_attr => "lat"
> > set_property :longitude_attr => "lng"
> > has status, starts_at, expires_at
> > end
> > end
>
> > class Campaign < ActiveRecord::Base
> > belongs_to :promotion
> > belongs_to :site
> > end
>
> > class Site < ActiveRecord::Base
> > acts_as_mappable
>
> > # associations
> > has_many :campaigns, :dependent => :destroy
> > has_many :promotions, :through => :campaigns
> > end
>
> > When I call Promotion.search I only get results for the promotions
> > that have a single record in Campaigns. So, If I have a Promotion that
> > is associated with more than 1 Site, I don't get any results back for
> > that Promotion. For example, I might have a Promotion with a title of
> > 'widgets' that is available in Birmingham and London. If I search with
> > the keyword 'widget' and location 'London', I would expect my search
> > to return the promotion, but, it doesn't. If I delete from the
> > Campaigns table the row that associates the promotion to the site in
> > Birmingham, and search again, the promotion gets returned
> > successfully.
>
> > Can anyone advise why this is, and what I need to change about my
> > search to be able to return Promotions that are associated with more
> > than one site?
>
> > Thanks for all your help
> > Alex
>
> > --
> > 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
> > athttp://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.