diff options
-rw-r--r-- | app/controllers/projects/labels_controller.rb | 5 | ||||
-rw-r--r-- | app/finders/labels_finder.rb | 7 | ||||
-rw-r--r-- | app/models/label.rb | 12 |
3 files changed, 23 insertions, 1 deletions
diff --git a/app/controllers/projects/labels_controller.rb b/app/controllers/projects/labels_controller.rb index ce03b2d8d1d..8a2bce6e7b5 100644 --- a/app/controllers/projects/labels_controller.rb +++ b/app/controllers/projects/labels_controller.rb @@ -160,7 +160,10 @@ class Projects::LabelsController < Projects::ApplicationController def find_labels @available_labels ||= - LabelsFinder.new(current_user, project_id: @project.id, include_ancestor_groups: params[:include_ancestor_groups]).execute + LabelsFinder.new(current_user, + project_id: @project.id, + include_ancestor_groups: params[:include_ancestor_groups], + search: params[:search]).execute end def authorize_admin_labels! diff --git a/app/finders/labels_finder.rb b/app/finders/labels_finder.rb index afd1f824b32..de2eeee122d 100644 --- a/app/finders/labels_finder.rb +++ b/app/finders/labels_finder.rb @@ -14,6 +14,7 @@ class LabelsFinder < UnionFinder @skip_authorization = skip_authorization items = find_union(label_ids, Label) || Label.none items = with_title(items) + items = by_search(items) sort(items) end @@ -63,6 +64,12 @@ class LabelsFinder < UnionFinder items.where(title: title) end + def by_search(labels) + return labels unless params[:search].present? + + labels.search(params[:search]) + end + # Gets redacted array of group ids # which can include the ancestors and descendants of the requested group. def group_ids_for(group) diff --git a/app/models/label.rb b/app/models/label.rb index 7bbcaa121ca..7b08547fa6e 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -2,6 +2,7 @@ class Label < ActiveRecord::Base include CacheMarkdownField include Referable include Subscribable + include Gitlab::SQL::Pattern # Represents a "No Label" state used for filtering Issues and Merge # Requests that have no label assigned. @@ -103,6 +104,17 @@ class Label < ActiveRecord::Base nil end + # Searches for labels with a matching title or description. + # + # This method uses ILIKE on PostgreSQL and LIKE on MySQL. + # + # query - The search query as a String. + # + # Returns an ActiveRecord::Relation. + def self.search(query) + fuzzy_search(query, [:title, :description]) + end + def open_issues_count(user = nil) issues_count(user, state: 'opened') end |