diff options
-rw-r--r-- | app/models/label.rb | 7 | ||||
-rw-r--r-- | changelogs/unreleased/allow-filtering-labels-by-a-single-character.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/sql/pattern.rb | 6 | ||||
-rw-r--r-- | spec/finders/labels_finder_spec.rb | 6 |
4 files changed, 23 insertions, 1 deletions
diff --git a/app/models/label.rb b/app/models/label.rb index 1c3db3eb35d..96bdb7f17c5 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -126,6 +126,13 @@ class Label < ActiveRecord::Base fuzzy_search(query, [:title, :description]) end + # Override Gitlab::SQL::Pattern.min_chars_for_partial_matching as + # label queries are never global, and so will not use a trigram + # index. That means we can have just one character in the LIKE. + def self.min_chars_for_partial_matching + 1 + end + def open_issues_count(user = nil) issues_count(user, state: 'opened') end diff --git a/changelogs/unreleased/allow-filtering-labels-by-a-single-character.yml b/changelogs/unreleased/allow-filtering-labels-by-a-single-character.yml new file mode 100644 index 00000000000..31165bbadb7 --- /dev/null +++ b/changelogs/unreleased/allow-filtering-labels-by-a-single-character.yml @@ -0,0 +1,5 @@ +--- +title: Allow filtering labels list by one or two characters +merge_request: 26012 +author: +type: changed diff --git a/lib/gitlab/sql/pattern.rb b/lib/gitlab/sql/pattern.rb index 07d0acdbae9..b698391c8bd 100644 --- a/lib/gitlab/sql/pattern.rb +++ b/lib/gitlab/sql/pattern.rb @@ -23,8 +23,12 @@ module Gitlab end end + def min_chars_for_partial_matching + MIN_CHARS_FOR_PARTIAL_MATCHING + end + def partial_matching?(query) - query.length >= MIN_CHARS_FOR_PARTIAL_MATCHING + query.length >= min_chars_for_partial_matching end # column - The column name to search in. diff --git a/spec/finders/labels_finder_spec.rb b/spec/finders/labels_finder_spec.rb index 9abc52aa664..3f060ba0553 100644 --- a/spec/finders/labels_finder_spec.rb +++ b/spec/finders/labels_finder_spec.rb @@ -209,6 +209,12 @@ describe LabelsFinder do expect(finder.execute).to eq [project_label_1] end + + it 'returns labels matching a single character' do + finder = described_class.new(user, search: '(') + + expect(finder.execute).to eq [group_label_1] + end end context 'filter by subscription' do |