diff options
author | Rémy Coutable <remy@rymai.me> | 2016-03-18 23:29:18 +0100 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-03-18 23:29:18 +0100 |
commit | cafa408b2521aa82d856581eb5d78d98114f1ab2 (patch) | |
tree | 5172e0c5555354d0275c6bf830bdd25e2e116d1c /app/models/namespace.rb | |
parent | 0b942541da1dc616cea266dc1f4d517fe81f6e5a (diff) | |
parent | 18fc7c66f4455e757593a60e02a6306decef5a47 (diff) | |
download | gitlab-ce-cafa408b2521aa82d856581eb5d78d98114f1ab2.tar.gz |
Merge remote-tracking branch 'origin/master' into remove-wip
Diffstat (limited to 'app/models/namespace.rb')
-rw-r--r-- | app/models/namespace.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb index bdb33f37495..55842df1e2d 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -52,8 +52,18 @@ class Namespace < ActiveRecord::Base find_by("lower(path) = :path OR lower(name) = :path", path: path.downcase) end + # Searches for namespaces 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("name LIKE :query OR path LIKE :query", query: "%#{query}%") + t = arel_table + pattern = "%#{query}%" + + where(t[:name].matches(pattern).or(t[:path].matches(pattern))) end def clean_path(path) |