summaryrefslogtreecommitdiff
path: root/app/models/user.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-03-01 16:08:48 +0100
committerRobert Speicher <rspeicher@gmail.com>2016-03-11 15:25:21 -0500
commit800aa296953c4a99e16e0493d9260359ef8c8414 (patch)
tree32f4959ceb8c58dca1a6bed8acf9baf1728e44ec /app/models/user.rb
parent508b6b46fea6b4bae9ce19c0337bafdb694edda8 (diff)
downloadgitlab-ce-800aa296953c4a99e16e0493d9260359ef8c8414.tar.gz
Use ILIKE/LIKE for searching users
Diffstat (limited to 'app/models/user.rb')
-rw-r--r--app/models/user.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 505a547d8ec..fc4cf92be60 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -286,8 +286,22 @@ class User < ActiveRecord::Base
end
end
+ # Searches users matching the given query.
+ #
+ # This method uses ILIKE on PostgreSQL and LIKE on MySQL.
+ #
+ # query - The search query as a String
+ #
+ # Returns an ActiveRecord::Relation.
def search(query)
- where("lower(name) LIKE :query OR lower(email) LIKE :query OR lower(username) LIKE :query", query: "%#{query.downcase}%")
+ table = User.arel_table
+ pattern = "%#{query}%"
+
+ where(
+ table[:name].matches(pattern).
+ or(table[:email].matches(pattern)).
+ or(table[:username].matches(pattern))
+ )
end
def by_login(login)