【问题标题】:Is there a way to use facets with the pg_search gem有没有办法在 pg_search gem 中使用 facets
【发布时间】:2011-10-20 15:14:29
【问题描述】:

我想在标准搜索的基础上使用构面。有没有办法使用 pg_search 使搜索结果本身通过构面“搜索”?

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

例子:

1) 搜索带有单词“test”的博客

2) 点击链接仅获取之前结果中同样在 6 月发布的文章

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 postgresql full-text-search pg-search


    【解决方案1】:

    我是pg_search的原作者和维护者。

    pg_search_scope 与任何其他 Active Record 作用域一样工作,因此您可以将它们链接起来。

    假设您有一个模型 Blog 和一个名为 search_titlepg_search_scope 和另一个名为 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 这样的分页解决方案。

    【讨论】:

      猜你喜欢
      • 2018-09-13
      • 2020-02-08
      • 1970-01-01
      • 2013-07-07
      • 1970-01-01
      • 2021-10-02
      • 1970-01-01
      • 2020-06-10
      • 1970-01-01
      相关资源
      最近更新 更多