[英]How do I implement advanced search with operators with pg_search?
I have implemented PgSearch on my Node
model like so: 我在我的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]
}
And in my controller I have this: 在我的控制器中我有这个:
if params[:search]
@nodes = Node.node_search(params[:search])
end
Ideally, what I would like to be able to do though, is have someone be able to type in the text representation (a flag) of one of the associations and have the search filter just on that flag. 理想情况下,我希望能够做到的是,有人能够键入其中一个关联的文本表示(标志),并且只对该标志进行搜索过滤。
Eg say: "name: Bouncing Ball", where the search would take place just on the column called name
on the nodes
model. 例如说:“name:Bouncing Ball”,搜索将发生在nodes
模型上名为name
的列上。 Aka...it would look for all the nodes with the name Bouncing Ball
and not search other columns or models or even any of the associations. Aka ...它会查找名为Bouncing Ball
所有节点,而不是搜索其他列或模型甚至任何关联。
Naturally, I would like to be able to do searches like: owner: John Brown
(which searches for all nodes whose owner/user first_name and last_name are John Brown), comment: Manhattan
(which searches for all nodes that have a comment with the text Manhattan
in the copy, and so on. 当然,我希望能够执行以下搜索: owner: John Brown
(搜索其所有者/用户first_name和last_name为John Brown的所有节点), comment: Manhattan
(搜索所有具有注释的节点)文本Manhattan
中的副本,等等。
How do I achieve this with PgSearch? 如何使用PgSearch实现这一目标?
Have you tried to use a combinations of " Dynamic search scopes " with some controller processing of the search string? 您是否尝试将“ 动态搜索范围 ”与搜索字符串的某些控制器处理结合使用?
name: Bob
, parse out the columns/relationship and the searching value then pass it to a pg_search_scope with a lambda block? name: Bob
,解析列/关系和搜索值,然后将其传递给带有lambda块的pg_search_scope?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.