我有两个模型发布和评论,我想用思维sphinx搜索两个,我在单个模型上工作正常,但在搜索两个模型时给我错误“未定义方法`sphinx_index_options'用于Object:Class”。
我遇到的错误 错误“对象的未定义方法`sphinx_index_options”:类“
在Post模型中是
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
和评论模型
define_index do
indexes [body, other], as: :comment
has created_at
end
belongs_to :commentable, :polymorphic => true
并且在我的控制器查询中
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 其他 render:action => :search_form, 端
答案 0 :(得分:2)
这是因为单表继承。更新你的思维sphinx gem~> 2.0.12。
答案 1 :(得分:1)
您需要在索引之前定义关系。