2012-09-28 81 views
0

我不知道如何從當前帖子搜索評論。如果我使用像太陽黑子Solr。如何從帖子搜索評論

searchable :auto_index => true do 
    text :description 
end 

評論,但是,我想從帖子搜索像

@search = @post.comments.search 

和我從數據庫中的所有評論,但不僅從目前的職位。爲什麼? ((

回答

0

在模型中沒有參數:

searchable :auto_index => true do 
    text :description 
    integer :post_id 
end 

,並在控制器

Comment.search do 
    fulltext params[:query]   if params[:query].present? 
    with :post_id, params[:post_id] if params[:post_id].present? 
end