简体   繁体   English

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

[英]Is there a way to use facets with the pg_search gem

I'd like to use facets in plus of standard search. 我想在标准搜索中使用facet。 Is there a way to make search results be itself "searched" with facets using pg_search? 有没有办法让搜索结果本身使用pg_search与facet“搜索”?

As far as I can tell, pg_search_scope are mutually exclusive (is there a workaround?). 据我所知,pg_search_scope是互斥的(有解决方法吗?)。 Thanks! 谢谢!

Example: 例:

1) search blogs with word "test" 1)用“测试”一词搜索博客

2) click link to get only articles from previous result that were also posted in june 2)单击链接以仅获取也在6月发布的先前结果的文章

I'm the original author and maintainer of pg_search . 我是pg_search原作者和维护者。

A pg_search_scope works like any other Active Record scope, so you can chain them. pg_search_scope与任何其他Active Record范围一样,因此您可以链接它们。

So let's say you have a model Blog with a pg_search_scope named search_title and another scope named in_month that takes two parameters, a month number and a year number. 因此,假设您有一个模型Blog ,其中pg_search_scope名为search_title ,另一个范围名为in_month ,它in_month两个参数,一个月号和一个年号。 Something like this: 像这样的东西:

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

Then you can call it like this: 然后你可以像这样调用它:

Blog.search_title("broccoli").in_month(6, 2011)

The reverse should also work: 反过来也应该有效:

Blog.in_month(6, 2011).search_title("broccoli")

And pagination solutions like Kaminari could also be called on the end. 像Kaminari这样的分页解决方案也可以在最后调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM