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",搜索将name在nodes模型上调用的列上进行.Aka ...它会查找具有名称的所有节点,Bouncing Ball而不是搜索其他列或模型甚至任何关联.
当然,我希望能够执行以下搜索:(
owner: John Brown搜索其所有者/用户first_name和last_name是John Brown comment: Manhattan的所有节点),(搜索所有Manhattan在副本中都有文本注释的节点,等等上.
如何使用PgSearch实现这一目标?
| 归档时间: |
|
| 查看次数: |
713 次 |
| 最近记录: |