Overlap partial_matching? function
What does this MR do and why?
Hi, Gitlab
We found one issue related with fuzzy search issue.
When user search 2 Chinese chars and sort with priority
, gitlab will NOT enable fuzzy search, however search 2 Chinese chars and sort created
, gitlab will enable fuzzy search.
In JiHu, even fuzzy search a one Chinese character is meaningful to user, no matter which field is sorted, so we need enable fuzzy search always.
after reading the code, we found the key method partial_matching?
of fuzzy search, which will compare query.length
with min_chars_for_partial_matching
, which disable fuzzy search when query.length
less than 3.
following is the partial_matching?
method code
# gitlab/lib/gitlab/sql/pattern.rb
def partial_matching?(query, use_minimum_char_limit: true)
return true unless use_minimum_char_limit
query.length >= min_chars_for_partial_matching
end
Even there is param use_minimum_char_limit
in partial_matching?
method to control the method result, but we still cannot use it, because this param value depend on method use_cte_for_search?
when we search issue and sort with priority
, which disable fuzzy search.
following is the issue search code
# app/finders/issuable_finder.rb
def by_search(items)
...
# if use_cte_for_search? is false, it will require minimum chat limit to enable fuzzy_search
items.full_search(search, matched_columns: params[:in], use_minimum_char_limit: !use_cte_for_search?)
end
def use_cte_for_search?
strong_memoize(:use_cte_for_search) do
next false unless search
# when sort with priority during search, this method will return false
next false unless default_or_simple_sort?
attempt_group_search_optimizations? || attempt_project_search_optimizations?
end
end
so we need prepend method partial_matching?
, and since method partial_matching?
belongs to class method in ActiveConcern, so not only we need prepend Gitlab::SQL::Pattern
, but also need prepend Gitlab::SQL::Pattern::ClassMethods
, you can find similar example in IssueableLink
Screenshots or screen recordings
this link search “审计” with priority sort, https://gitlab.com/wd665544/issue-test/-/issues/?search=%E5%AE%A1%E8%AE%A1&sort=priority_desc&state=opened&first_page_size=20 should show 3 issues, but only show 1
this link search “审计” with created_at sort, https://gitlab.com/wd665544/issue-test/-/issues/?search=%E5%AE%A1%E8%AE%A1&sort=created_date&state=opened&first_page_size=20
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.