使用包含空格的术语搜索AR

时间:2013-03-19 14:51:43

标签: ruby-on-rails-3 postgresql activerecord where

我在Rails中有这行代码

 @people = User.where("firstname @@ :query or lastname @@ :query", query: @query )

如果单独搜索JoeSmith,这可以很好地找到名为Joe Smith的用户。

如果搜索Joe Smith

,如何更改此行以获取用户?

1 个答案:

答案 0 :(得分:1)

@people = User.where("firstname @@ :query OR lastname @@ :query OR ((firstname || " " || lastname) = ?) @@ :query", query: @query )

请参阅How to concat two fields in Postgresql

相关问题