summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-03-01 15:43:19 +0100
committerRobert Speicher <rspeicher@gmail.com>2016-03-11 15:25:21 -0500
commit508b6b46fea6b4bae9ce19c0337bafdb694edda8 (patch)
tree38cf1882f185c23205325a4660e8abebe1aebf89 /app/models
parent1f5284e5ddf2ce9b555799f43ca73be32d9bdf67 (diff)
downloadgitlab-ce-508b6b46fea6b4bae9ce19c0337bafdb694edda8.tar.gz
Use ILIKE/LIKE for searching notes
Diffstat (limited to 'app/models')
-rw-r--r--app/models/note.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index 3b20d5d22b6..76e86fdbcaa 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -105,8 +105,18 @@ class Note < ActiveRecord::Base
[:discussion, type.try(:underscore), id, line_code].join("-").to_sym
end
+ # Searches for notes 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(note) like :query", query: "%#{query.downcase}%")
+ table = Note.arel_table
+ pattern = "%#{query}%"
+
+ where(table[:note].matches(pattern))
end
def grouped_awards