summaryrefslogtreecommitdiff
path: root/app/models/group.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-03-01 16:15:42 +0100
committerRobert Speicher <rspeicher@gmail.com>2016-03-11 15:25:21 -0500
commitce5e831bcfd7daf1a12d488e2857d9424de091dd (patch)
tree3fba12811c386e36349c54f2205db0640ef4351d /app/models/group.rb
parent800aa296953c4a99e16e0493d9260359ef8c8414 (diff)
downloadgitlab-ce-ce5e831bcfd7daf1a12d488e2857d9424de091dd.tar.gz
Use ILIKE/LIKE for searching groups
Diffstat (limited to 'app/models/group.rb')
-rw-r--r--app/models/group.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/app/models/group.rb b/app/models/group.rb
index 76042b3e3fd..bfeddf8b4d2 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -33,8 +33,18 @@ class Group < Namespace
after_destroy :post_destroy_hook
class << self
+ # Searches for groups 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(namespaces.name) LIKE :query or LOWER(namespaces.path) LIKE :query", query: "%#{query.downcase}%")
+ table = Group.arel_table
+ pattern = "%#{query}%"
+
+ where(table[:name].matches(pattern).or(table[:path].matches(pattern)))
end
def sort(method)