Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2019-02-05 12:52:40 +0300
committerSean McGivern <sean@gitlab.com>2019-02-05 12:52:40 +0300
commit068b41275f6f142acfddca273ace68d03a6c0730 (patch)
treec3f4c927ede7a09242f16771481a0cb7f627fc91 /app/models/concerns/issuable.rb
parenta34d6abd3b2ee98b0a68b4571c7de61321b4a3ce (diff)
parent40198f81843b315f2eb1c1a1a65292b6fc61f9d7 (diff)
Merge branch 'search-title' into 'master'
Add 'in' filter that modifies scope of 'search' filter to issues and merge requests API See merge request gitlab-org/gitlab-ce!24350
Diffstat (limited to 'app/models/concerns/issuable.rb')
-rw-r--r--app/models/concerns/issuable.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index b1cf03551f6..0a77fbeba08 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -136,10 +136,18 @@ module Issuable
# This method uses ILIKE on PostgreSQL and LIKE on MySQL.
#
# query - The search query as a String
+ # matched_columns - Modify the scope of the query. 'title', 'description' or joining them with a comma.
#
# Returns an ActiveRecord::Relation.
- def full_search(query)
- fuzzy_search(query, [:title, :description])
+ def full_search(query, matched_columns: 'title,description')
+ allowed_columns = [:title, :description]
+ matched_columns = matched_columns.to_s.split(',').map(&:to_sym)
+ matched_columns &= allowed_columns
+
+ # Matching title or description if the matched_columns did not contain any allowed columns.
+ matched_columns = [:title, :description] if matched_columns.empty?
+
+ fuzzy_search(query, matched_columns)
end
def sort_by_attribute(method, excluded_labels: [])