summaryrefslogtreecommitdiff
path: root/lib/gitlab
diff options
context:
space:
mode:
authorMario de la Ossa <mariodelaossa@gmail.com>2019-06-12 18:08:44 -0600
committerMario de la Ossa <mariodelaossa@gmail.com>2019-07-04 10:56:13 -0600
commit4f04c4c90b2db8ddcf5f3e28a9bbefd20c8bbda0 (patch)
treeb71cc9aca9c6a59a77281c4ec80e4c260b2c0b86 /lib/gitlab
parent62e52ac6a8130c080f498ee2f76ef50b8c209f0f (diff)
downloadgitlab-ce-4f04c4c90b2db8ddcf5f3e28a9bbefd20c8bbda0.tar.gz
Ignore min_chars_for_partial_matching unles trigrm40379-CJK-search-min-chars
If we're not using a trigram index, then ignore the min_chars_for_partial_matching setting
Diffstat (limited to 'lib/gitlab')
-rw-r--r--lib/gitlab/sql/pattern.rb24
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/gitlab/sql/pattern.rb b/lib/gitlab/sql/pattern.rb
index fd108b4c124..f6edbfced7f 100644
--- a/lib/gitlab/sql/pattern.rb
+++ b/lib/gitlab/sql/pattern.rb
@@ -9,14 +9,16 @@ module Gitlab
REGEX_QUOTED_WORD = /(?<=\A| )"[^"]+"(?= |\z)/.freeze
class_methods do
- def fuzzy_search(query, columns)
- matches = columns.map { |col| fuzzy_arel_match(col, query) }.compact.reduce(:or)
+ def fuzzy_search(query, columns, use_minimum_char_limit: true)
+ matches = columns.map do |col|
+ fuzzy_arel_match(col, query, use_minimum_char_limit: use_minimum_char_limit)
+ end.compact.reduce(:or)
where(matches)
end
- def to_pattern(query)
- if partial_matching?(query)
+ def to_pattern(query, use_minimum_char_limit: true)
+ if partial_matching?(query, use_minimum_char_limit: use_minimum_char_limit)
"%#{sanitize_sql_like(query)}%"
else
sanitize_sql_like(query)
@@ -27,7 +29,9 @@ module Gitlab
MIN_CHARS_FOR_PARTIAL_MATCHING
end
- def partial_matching?(query)
+ def partial_matching?(query, use_minimum_char_limit: true)
+ return true unless use_minimum_char_limit
+
query.length >= min_chars_for_partial_matching
end
@@ -35,14 +39,14 @@ module Gitlab
# query - The text to search for.
# lower_exact_match - When set to `true` we'll fall back to using
# `LOWER(column) = query` instead of using `ILIKE`.
- def fuzzy_arel_match(column, query, lower_exact_match: false)
+ def fuzzy_arel_match(column, query, lower_exact_match: false, use_minimum_char_limit: true)
query = query.squish
return unless query.present?
- words = select_fuzzy_words(query)
+ words = select_fuzzy_words(query, use_minimum_char_limit: use_minimum_char_limit)
if words.any?
- words.map { |word| arel_table[column].matches(to_pattern(word)) }.reduce(:and)
+ words.map { |word| arel_table[column].matches(to_pattern(word, use_minimum_char_limit: use_minimum_char_limit)) }.reduce(:and)
else
# No words of at least 3 chars, but we can search for an exact
# case insensitive match with the query as a whole
@@ -56,7 +60,7 @@ module Gitlab
end
end
- def select_fuzzy_words(query)
+ def select_fuzzy_words(query, use_minimum_char_limit: true)
quoted_words = query.scan(REGEX_QUOTED_WORD)
query = quoted_words.reduce(query) { |q, quoted_word| q.sub(quoted_word, '') }
@@ -67,7 +71,7 @@ module Gitlab
words.concat(quoted_words)
- words.select { |word| partial_matching?(word) }
+ words.select { |word| partial_matching?(word, use_minimum_char_limit: use_minimum_char_limit) }
end
end
end