2012-09-28 82 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