有没有办法在pg_search gem中使用facet

mon*_*ike 6 postgresql full-text-search ruby-on-rails ruby-on-rails-3 pg-search

我想在标准搜索中使用facet.有没有办法让搜索结果本身使用pg_search与facet"搜索"?

据我所知,pg_search_scope是互斥的(有解决方法吗?).谢谢!

例:

1)用"测试"一词搜索博客

2)单击链接以仅获取也在6月发布的先前结果的文章

Gra*_*ins 8

我是原作者和维护者pg_search.

A pg_search_scope可以像任何其他Active Record范围一样工作,因此您可以链接它们.

所以假设你有一个Blog带有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
Run Code Online (Sandbox Code Playgroud)

然后你可以像这样调用它:

Blog.search_title("broccoli").in_month(6, 2011)
Run Code Online (Sandbox Code Playgroud)

反过来也应该有效:

Blog.in_month(6, 2011).search_title("broccoli")
Run Code Online (Sandbox Code Playgroud)

像Kaminari这样的分页解决方案也可以在最后调用.