summaryrefslogtreecommitdiff
path: root/app/models/milestone.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-03-01 17:05:26 +0100
committerRobert Speicher <rspeicher@gmail.com>2016-03-11 15:25:22 -0500
commit2cf7f3f410832560bf049b24fbcaa27c1e3f30c7 (patch)
tree39e97a7c0d99ac97b98ed28d11a12dae11c109d5 /app/models/milestone.rb
parent87e7c3e1321ac5ae26d6a23d7b16e8dadaff98d2 (diff)
downloadgitlab-ce-2cf7f3f410832560bf049b24fbcaa27c1e3f30c7.tar.gz
Use ILIKE/LIKE for searching milestones
Diffstat (limited to 'app/models/milestone.rb')
-rw-r--r--app/models/milestone.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/app/models/milestone.rb b/app/models/milestone.rb
index e3969f32dd6..e3b6c552f92 100644
--- a/app/models/milestone.rb
+++ b/app/models/milestone.rb
@@ -58,9 +58,18 @@ class Milestone < ActiveRecord::Base
alias_attribute :name, :title
class << self
+ # Searches for milestones 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)
- query = "%#{query}%"
- where("title like ? or description like ?", query, query)
+ t = arel_table
+ pattern = "%#{query}%"
+
+ where(t[:title].matches(pattern).or(t[:description].matches(pattern)))
end
end