如何使用pg_search对运算符实现高级搜索?

mar*_*ion 10 postgresql ruby-on-rails pg-search ruby-on-rails-4

我在我的Node模型上实现了PgSearch,如下所示:

include PgSearch
pg_search_scope :node_search, against: [:name, :user_id, :circa],
    using: { tsearch: { any_word: true} },
    :associated_against => {
      comments: [:message],
      user: [:first_name, :last_name, :email],
      memberships: [:relation]
    }
Run Code Online (Sandbox Code Playgroud)

在我的控制器中我有这个:

if params[:search]
  @nodes = Node.node_search(params[:search])
end
Run Code Online (Sandbox Code Playgroud)

理想情况下,我希望能够做到的是,有人能够键入其中一个关联的文本表示(标志),并且只对该标志进行搜索过滤.

例如:"name:Bouncing Ball",搜索将namenodes模型上调用的列上进行.Aka ...它会查找具有名称的所有节点,Bouncing Ball而不是搜索其他列或模型甚至任何关联.

当然,我希望能够执行以下搜索:( owner: John Brown搜索其所有者/用户first_name和last_name是John Brown comment: Manhattan的所有节点),(搜索所有Manhattan在副本中都有文本注释的节点,等等上.

如何使用PgSearch实现这一目标?

Bil*_*ill 4

您是否尝试过将“动态搜索范围”与搜索字符串的某些控制器处理结合使用?

name: Bob,解析出列/关系和搜索值,然后将其传递给带有 lambda 块的 pg_search_scope?