简体   繁体   中英

thinking sphinx multiple classes

I have two models Post and comment and i want to search both using thinking sphinx, I is working fine with single model but give me error "undefined method `sphinx_index_options' for Object:Class" while search both models.

ERROR I faced error "undefined method `sphinx_index_options' for Object:Class"

In Post model is

define_index do
indexes [topic, body], as: :post
has cached_tag_list, :as => :tag_ids
indexes comments.body, :as => :comment
has created_at 
where "is_private='f'"
end
has_many :comments, :as=>:commentable, :order => "created_at asc", :dependent =>:destroy

and comments model

define_index do
indexes [body, other], as: :comment
has created_at
end
belongs_to :commentable, :polymorphic => true

and in my controller query is

if params[:query]
@query = params[:query]
page = params[:page] || 1
@search = ThinkingSphinx.search @query, :classes=>[Post, Comment],    :order=>:created_at, :sort_mode=>:desc, :field_weights=>{:topic=>2.0}, :per_page=>15, :page=>page

@total_entries = @search.total_entries else render :action => :search_form, end

It's because of Single Table Inheritance. Update your thinking sphinx gem ~> 2.0.12.

您需要在索引之前定义关系。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM