我想在标准搜索中使用facet.有没有办法让搜索结果本身使用pg_search与facet“搜索”?
据我所知,pg_search_scope是互斥的(有解决方法吗?).
谢谢!
例:
1)用“测试”一词搜索博客
2)单击链接以仅获取也在6月发布的先前结果的文章
解决方法
我是pg_search的原作者和维护者.
pg_search_scope与任何其他Active Record范围一样,因此您可以链接它们.
因此,假设您有一个模型博客,其中pg_search_scope名为search_title,另一个范围名为in_month,它带有两个参数,一个月号和一个年号.像这样的东西:
class Blog < ActiveRecord::Base include PgSearch pg_search_scope :search_title,:against => :title scope :in_month,lambda { |month_number,year_number| where(:month => month_number,:year => year_number) } end
然后你可以像这样调用它:
Blog.search_title("broccoli").in_month(6,2011)
反过来也应该有效:
Blog.in_month(6,2011).search_title("broccoli")
像Kaminari这样的分页解决方案也可以在最后调用.