Sphinx thinking is based on associations in the model. In normal situations, you only need to establish the definition of your associations.
With the act_as_taggable_on plugin, you do not have any tag associations in the model file and when writing
indexes tags.name ,: as =>: tags
TS interprets this as:
CAST(`announcements`.`name` AS CHAR) AS `tags`
(look at sql_query in the development.sphinx.conf file, in my case). I believe that you have an attribute name in the model declaration and does not start when an error occurs while restoring the index.
But we expect:
CAST(GROUP_CONCAT(DISTINCT IFNULL(`tags`.`name`, '0') SEPARATOR ' ') AS CHAR) AS `tags`
and
LEFT OUTER JOIN `taggings` ON (`announcements`.`id` = `taggings`.`taggable_id`) LEFT OUTER JOIN `tags` ON (`tags`.`id` = `taggings`.`tag_id`) AND taggings.taggable_type = 'Announcement'
To get the job done, just add the tag associations to your model before rebuilding the index:
class Announcement < ActiveRecord::Base acts_as_taggable_on :tags,:category has_many :taggings, :as => :taggable, :dependent => :destroy, :include => :tag, :class_name => "ActsAsTaggableOn::Tagging", :conditions => "taggings.taggable_type = 'Announcement'" #for context-dependent tags: has_many :category_tags, :through => :taggings, :source => :tag, :class_name => "ActsAsTaggableOn::Tag", :conditions => "taggings.context = 'categories'"
In define_index :
indexes category_tags(:name), :as => :tags has category_tags(:id), :as => :tag_ids, :facet => true
In the controller:
@announcement_facets = Announcement.facets params[:search], :with => {:tag_ids => [...]} @announcements = @announcement_facets.for.paginate( :page => params[:page], :per_page => 10 )