I'm a little stuck on getting polymorphism working with Thinking Sphinx, 
and I was wondering if anyone could help me resolve my problem.

I have three models -- Specialist, Center, and Address -- where a Center 
can have many Specialists, and both Specialists and Centers can have many 
Addresses. (Specialists should have addresses when they work in a home 
office or something, otherwise they should belong to a Center).

I want to geosearch on both specialists and centers, such that the results 
can be presented in accordance to distance/relevance as either:

   - a specialist with the specialist's address(es), or 
   - a center with its address (and a dropdown listing the associated 
   specialists who matched the search criteria)
   

My models are set up as follows:

class Center < ActiveRecord::Base
>   has_many :services
>   has_many :specialists, :through => :services
>   has_many :participants, :through => :services
>   has_many :addresses, :as => :addressable
>   accepts_nested_attributes_for :addresses
>   attr_accessible :name, :desc, :email, :phone, :website, :services, 
> :participant_ids, :specialist_ids, :addresses_attributes
> end 
>
 

> class Specialist < ActiveRecord::Base
>   has_many :services
>   has_many :participants, :through => :services
>   has_many :centers, :through => :services
>   
>   has_many :addresses, :as => :addressable
>   accepts_nested_attributes_for :addresses
>   
>   attr_accessible :desc, :name, :phone, :email, :website, 
> :participant_ids, :center_ids, :addresses_attributes
> end
>
 

> class Address < ActiveRecord::Base
>   attr_accessible :address, :addressable_id, :addressable_type, :admin1, 
> :city, :country, :latitude, :longitude
>   belongs_to :addressable, :polymorphic => true
> end


And here is my Thinking Sphinx index for Address:

ThinkingSphinx::Index.define :address, :with => :active_record do
>   #fields
>   indexes addresses.addressable(:desc), :as => :desc
>   #indexes addressable(:desc), :as => :desc
>   #polymorphs address, :to => %w(Specilaists Centers)
>   #polymorphs addresses.addressable, to: %w(Specialist Center)
>   
>   #attributes
>   has "RADIANS(latitude)", :as => :latitude, :type => :float
>   has "RADIANS(longitude)", :as => :longitude, :type => :float
>   #properties
>   #set_property :delta => true
>   #set_property :enable_star => true
> end



So far, I've tried a lot of different combinations of suggestions for the 
index file that I've found online, but I get one of three errors during 
indexing:

   - ERROR: index 'address_core': sql_range_query: You have an error in 
   your SQL syntax; check the manual that corresponds to your MySQL server 
   version for the right syntax to use near 'AS `desc`, `addresses`.`id` AS 
   `sphinx_internal_id`, 'Address' AS `sphinx_intern' at line 1 
   (DSN=mysql://root:***@localhost:3306/geopenguin_development).
   - rake aborted! undefined method `options' for nil:NilClass
   - rake aborted! Can not eagerly load the polymorphic association 
   :addressable
   

I think my model associations are set up ok, because in rails console I can 
access one from another (address.addressable.desc, specialist.address, 
center.address, etc.). I have a few test records for all of them. Does 
anyone see something obviously wrong with my approach?

Thank you for all your help in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/d/optout.

Reply via email to