diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-03-01 15:43:19 +0100 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-03-11 15:25:21 -0500 |
commit | 508b6b46fea6b4bae9ce19c0337bafdb694edda8 (patch) | |
tree | 38cf1882f185c23205325a4660e8abebe1aebf89 /app | |
parent | 1f5284e5ddf2ce9b555799f43ca73be32d9bdf67 (diff) | |
download | gitlab-ce-508b6b46fea6b4bae9ce19c0337bafdb694edda8.tar.gz |
Use ILIKE/LIKE for searching notes
Diffstat (limited to 'app')
-rw-r--r-- | app/models/note.rb | 12 |
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 |