Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/models/queries/projects/filters/name_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ def where
["LOWER(projects.name) IN (?)", sql_value]
when "!"
["LOWER(projects.name) NOT IN (?)", sql_value]
when "~", "**"
when "~"
["LOWER(projects.name) LIKE ?", "%#{sql_value}%"]
when "**"
terms = values.first.downcase.split
conditions = Array.new(terms.size, "LOWER(projects.name) LIKE ?").join(" AND ")
[conditions, *terms.map { |t| "%#{t}%" }]
when "!~"
["LOWER(projects.name) NOT LIKE ?", "%#{sql_value}%"]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ export class OpHeaderProjectSelectComponent extends UntilDestroyedMixin implemen
(project) => {
const searchText = this.searchableProjectListService.searchText;
if (searchText.length) {
const matches = project.name.toLowerCase().includes(searchText.toLowerCase());
const terms = searchText.toLowerCase().split(/\s+/).filter((t) => t.length > 0);
const matches = terms.every((term) => project.name.toLowerCase().includes(term));

if (!matches) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ export class SearchableProjectListService {
return of([[] as IProject[], searchText, loadingEnabled as boolean, favoriteIds]);
}

const nameFilter:ApiV3ListFilter[] = [];
const searchFilter:ApiV3ListFilter[] = [];
if (searchText.length > 0) {
nameFilter.push(['name', '~', [searchText]]);
searchFilter.push(['typeahead', '**', [searchText]]);
}

return this.fetchProjects(nameFilter)
return this.fetchProjects(searchFilter)
.pipe(map((collection) => [collection._embedded.elements, searchText, loadingEnabled as boolean, favoriteIds]));
}),
switchMap(([projects, searchText, loadingEnabled, favoriteIds]:[IProject[],string,boolean,string[]]) => {
Expand Down
5 changes: 3 additions & 2 deletions spec/features/projects/project_autocomplete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@
expect(page).to have_no_css("strong")
end

# Expect fuzzy matches for plain
# Expect fuzzy matches for multiple substrings
top_menu.search "Plain pr"
top_menu.expect_result "Plain project"
top_menu.expect_no_result "Plain other project"
top_menu.expect_result "Plain other project"
Comment thread
NobodysNightmare marked this conversation as resolved.
top_menu.expect_no_result "Project with different name and identifier"

# Expect search to match names only and not the identifier
top_menu.clear_search
Expand Down
Loading