diff options
author | Hiroyuki Sato <sathiroyuki@gmail.com> | 2017-08-23 19:54:14 +0900 |
---|---|---|
committer | Hiroyuki Sato <sathiroyuki@gmail.com> | 2017-08-31 03:14:58 +0900 |
commit | 59e5393827e9e9eddb9bb0a960f1cda1f6d9511d (patch) | |
tree | 6bc579b71c2e6ec77832a9316355d25144032f99 /app/models/concerns/issuable.rb | |
parent | d6e956d3a89fbb7f1a503f152fe9a4e2ca931d85 (diff) | |
download | gitlab-ce-59e5393827e9e9eddb9bb0a960f1cda1f6d9511d.tar.gz |
Fuzzy search issuable title or description
Diffstat (limited to 'app/models/concerns/issuable.rb')
-rw-r--r-- | app/models/concerns/issuable.rb | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 3731b7c8577..681c3241dbb 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -6,6 +6,7 @@ # module Issuable extend ActiveSupport::Concern + include Gitlab::SQL::Pattern include CacheMarkdownField include Participable include Mentionable @@ -122,7 +123,9 @@ module Issuable # # Returns an ActiveRecord::Relation. def search(query) - where(arel_table[:title].matches("%#{query}%")) + title = to_fuzzy_arel(:title, query) + + where(title) end # Searches for records with a matching title or description. @@ -133,10 +136,10 @@ module Issuable # # Returns an ActiveRecord::Relation. def full_search(query) - t = arel_table - pattern = "%#{query}%" + title = to_fuzzy_arel(:title, query) + description = to_fuzzy_arel(:description, query) - where(t[:title].matches(pattern).or(t[:description].matches(pattern))) + where(title&.or(description)) end def sort(method, excluded_labels: []) |