Skip to content

Commit 6024c23

Browse files
committed
Support multi-substring search in project selector
1 parent bf9ba05 commit 6024c23

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

app/models/queries/projects/filters/name_filter.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ def where
4040
when "!"
4141
["LOWER(projects.name) NOT IN (?)", sql_value]
4242
when "~", "**"
43-
["LOWER(projects.name) LIKE ?", "%#{sql_value}%"]
43+
terms = values.first.downcase.split
44+
conditions = Array.new(terms.size, "LOWER(projects.name) LIKE ?").join(" AND ")
45+
[conditions, *terms.map { |t| "%#{t}%" }]
4446
when "!~"
4547
["LOWER(projects.name) NOT LIKE ?", "%#{sql_value}%"]
4648
end

frontend/src/app/shared/components/header-project-select/header-project-select.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export class OpHeaderProjectSelectComponent extends UntilDestroyedMixin implemen
8181
(project) => {
8282
const searchText = this.searchableProjectListService.searchText;
8383
if (searchText.length) {
84-
const matches = project.name.toLowerCase().includes(searchText.toLowerCase());
84+
const terms = searchText.toLowerCase().split(/\s+/).filter((t) => t.length > 0);
85+
const matches = terms.every((term) => project.name.toLowerCase().includes(term));
8586

8687
if (!matches) {
8788
return false;

spec/features/projects/project_autocomplete_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
create(:project, name:, identifier:, members: { user => role })
7979
end
8080
end
81+
8182
shared_let(:non_member_project) { create(:project) }
8283
shared_let(:public_project) { create(:public_project) }
8384

@@ -110,10 +111,10 @@
110111
expect(page).to have_no_css("strong")
111112
end
112113

113-
# Expect fuzzy matches for plain
114+
# Expect fuzzy matches for multiple substrings
114115
top_menu.search "Plain pr"
115116
top_menu.expect_result "Plain project"
116-
top_menu.expect_no_result "Plain other project"
117+
top_menu.expect_result "Plain other project"
117118

118119
# Expect search to match names only and not the identifier
119120
top_menu.clear_search

0 commit comments

Comments
 (0)