Thinking sphinx: Problems with polymorphic associations

Posted by auralbee on Stack Overflow See other posts from Stack Overflow or by auralbee
Published on 2010-04-27T10:41:29Z Indexed on 2010/04/27 10:43 UTC
Read the original article Hit count: 482

Hello,

I recently switched from ultrasphinx to thinking_sphinx for full-text search. I am trying to figure out how to index fields of polymorphic associations. I found some information but I still have some problems, although it seems to be easy. Here is my setup:

class Info < ActiveRecord::Base
 belongs_to :mappable, :polymorphic => true

 define_index
   indexes mappable_type
   indexes mappable(:name), :as => :mappable_name
end

class A < ActiveRecord::Base
 has_many :infos, :as => :mappable
end

class B < ActiveRecord::Base
 has_many :infos, :as => :mappable
end

Amongst others, I want to do a search in the name column of A and B (both classes have this column), so I added the field to my index.

When I do rake thinking_sphinx:index I get the following error:

Generating Configuration to .../config/development.sphinx.conf
rake aborted!
undefined method `connection' for Object:Class
.../.gem/ruby/1.8/gems/thinking-sphinx-1.3.16/lib/thinking_sphinx/
association.rb:149:in `casted_options'

Any idea? Am I missing something?

Thanks in advance. Tobi

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about thinking-sphinx