【发布时间】:2012-03-17 19:25:31
【问题描述】:
我有两个模型发布和评论,我想使用思维狮身人面像进行搜索,我在单个模型上工作正常,但在搜索两个模型时给我错误“未定义的方法 `sphinx_index_options' for 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
和cmets模型
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 别的 渲染 :action => :search_form, 结束
【问题讨论】:
-
error is undefined method `sphinx_index_options' for Object:Class
-
你能分享那个错误的堆栈跟踪吗?
-
由 Portal::PostsController#search 作为 HTML 参数处理:{"utf8"=>"✓", "query"=>"knee"} 用户负载 (1.7ms) SELECT "users"。 * FROM "users" WHERE "users"."id" = 1 LIMIT 1 Sphinx 查询 (21.5ms) 膝盖 Sphinx 找到 987 个结果在 45ms 内完成 500 内部服务器错误 NoMethodError (undefined method
sphinx_index_options' for Object:Class): app/controllers/portal/posts_controller.rb:123:insearch'
标签: jquery ruby-on-rails search model thinking-sphinx