From c9cca4e9245d4406cabeae0071a32774a0d0ed3e Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Fri, 13 Apr 2018 11:55:27 +0100 Subject: [PATCH 1/8] fixed project search (long names; literal terms) --- .../lazyloaded/lazyloaded-autocompleter.ts | 29 ++++++++++++++++- .../projects/project_autocomplete_spec.rb | 32 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/frontend/app/components/common/autocomplete/lazyloaded/lazyloaded-autocompleter.ts b/frontend/app/components/common/autocomplete/lazyloaded/lazyloaded-autocompleter.ts index 1a424a2890..6a8573802a 100644 --- a/frontend/app/components/common/autocomplete/lazyloaded/lazyloaded-autocompleter.ts +++ b/frontend/app/components/common/autocomplete/lazyloaded/lazyloaded-autocompleter.ts @@ -57,11 +57,38 @@ export abstract class ILazyAutocompleterBridge { private fuzzySearch(items:IAutocompleteItem[], term:string) { if (term === '') { return items; + } else if (term.length >= 3) { + const literalMatches = this.literalSearch(items, term); + + if (literalMatches.length > 0) { + return literalMatches as any; + } } return this.fuseInstance.search(term) as any; } + /** + * Filters the given list of items so that only items whose label contains + * the exact search term (case insensitive). + * + * @param items Items to be searched + * @param term Search term + * @return The subset of the given items matching the search term. + */ + private literalSearch(items:IAutocompleteItem[], term:string) { + const results:IAutocompleteItem[] = []; + const str:string = term.toLowerCase(); + + items.forEach(e => { + if (e.label.toLowerCase().indexOf(str) != -1) { + results.push(e); + } + }); + + return results; + } + /** * Allows to augment the set of matched items (e.g., to add hierarchy). * @param {IAutocompleteItem[]} items @@ -92,7 +119,7 @@ export abstract class ILazyAutocompleterBridge { tokenize: false, threshold: 0.2, location: 0, - distance: 100, + distance: 10000, // allow the term to appear anywere maxPatternLength: 16, minMatchCharLength: 2, keys: ['label'] diff --git a/spec/features/projects/project_autocomplete_spec.rb b/spec/features/projects/project_autocomplete_spec.rb index bde8ac59c0..9eb43ef289 100644 --- a/spec/features/projects/project_autocomplete_spec.rb +++ b/spec/features/projects/project_autocomplete_spec.rb @@ -51,6 +51,21 @@ describe 'Projects autocomplete page', type: :feature, js: true do identifier: 'plain-project-2') end + let!(:other_projects) do + names = [ + "Very long project name with term at the END", + "INK14 - Foo", + "INK15 - Bar", + "INK16 - Baz" + ] + + names.map do |name| + identifier = name.gsub(/[ \-]+/, "-") + + FactoryGirl.create :project, name: name, identifier: identifier + end + end + let(:top_menu) { ::Components::Projects::TopMenu.new } before do @@ -78,6 +93,23 @@ describe 'Projects autocomplete page', type: :feature, js: true do expect(page).to have_no_selector('.ui-menu-item-wrapper', text: 'Plain other project') end + # find terms at the end of project names + top_menu.search 'END' + with(top_menu.search_results) do + expect(page).to have_selector( + '.ui-menu-item-wrapper', + text: 'Very long project name with term at the END' + ) + end + + # Find literal matches exclusively if present + top_menu.search 'INK15' + within(top_menu.search_results) do + expect(page).to have_selector('.ui-menu-item-wrapper', text: 'INK15 - Bar') + expect(page).to have_no_selector('.ui-menu-item-wrapper', text: 'INK14 - Foo') + expect(page).to have_no_selector('.ui-menu-item-wrapper', text: 'INK16 - Baz') + end + # Expect hierarchy top_menu.clear_search From a412169cc781963ac3cafbb93b68cbffa8d27b09 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Fri, 13 Apr 2018 11:55:41 +0100 Subject: [PATCH 2/8] removed debug statement --- .../project-menu-autocomplete.component.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/app/components/projects/project-menu-autocomplete/project-menu-autocomplete.component.ts b/frontend/app/components/projects/project-menu-autocomplete/project-menu-autocomplete.component.ts index d155205fab..bd0cc6024e 100644 --- a/frontend/app/components/projects/project-menu-autocomplete/project-menu-autocomplete.component.ts +++ b/frontend/app/components/projects/project-menu-autocomplete/project-menu-autocomplete.component.ts @@ -196,7 +196,6 @@ export class ProjectMenuAutocompleteController extends ILazyAutocompleterBridge< */ protected augmentedResultSet(items:ProjectAutocompleteItem[], matched:ProjectAutocompleteItem[]) { const matches = matched.map(el => el.object.identifier); - console.log(matches); const matchedParents = _.flatten(matched.map(el => el.object.parents)); const results:ProjectAutocompleteItem[] = []; From da710db793a609ee685886ea9781897d288002d9 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Fri, 13 Apr 2018 12:00:45 +0100 Subject: [PATCH 3/8] fixed typo --- .../common/autocomplete/lazyloaded/lazyloaded-autocompleter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/app/components/common/autocomplete/lazyloaded/lazyloaded-autocompleter.ts b/frontend/app/components/common/autocomplete/lazyloaded/lazyloaded-autocompleter.ts index 6a8573802a..ea57ad3b10 100644 --- a/frontend/app/components/common/autocomplete/lazyloaded/lazyloaded-autocompleter.ts +++ b/frontend/app/components/common/autocomplete/lazyloaded/lazyloaded-autocompleter.ts @@ -119,7 +119,7 @@ export abstract class ILazyAutocompleterBridge { tokenize: false, threshold: 0.2, location: 0, - distance: 10000, // allow the term to appear anywere + distance: 10000, // allow the term to appear anywhere maxPatternLength: 16, minMatchCharLength: 2, keys: ['label'] From d40cf208e4f32e77a2aabffd3905a49df4677132 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Fri, 13 Apr 2018 13:00:47 +0100 Subject: [PATCH 4/8] code climate --- .../common/autocomplete/lazyloaded/lazyloaded-autocompleter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/app/components/common/autocomplete/lazyloaded/lazyloaded-autocompleter.ts b/frontend/app/components/common/autocomplete/lazyloaded/lazyloaded-autocompleter.ts index ea57ad3b10..de9e429379 100644 --- a/frontend/app/components/common/autocomplete/lazyloaded/lazyloaded-autocompleter.ts +++ b/frontend/app/components/common/autocomplete/lazyloaded/lazyloaded-autocompleter.ts @@ -81,7 +81,7 @@ export abstract class ILazyAutocompleterBridge { const str:string = term.toLowerCase(); items.forEach(e => { - if (e.label.toLowerCase().indexOf(str) != -1) { + if (e.label.toLowerCase().indexOf(str) !== -1) { results.push(e); } }); From c6fbbc13afbc6883ec7478f6efe99e03abc03a39 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Fri, 13 Apr 2018 13:01:02 +0100 Subject: [PATCH 5/8] fixed spec (invalid identifier as it needs downcast) --- spec/features/projects/project_autocomplete_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/projects/project_autocomplete_spec.rb b/spec/features/projects/project_autocomplete_spec.rb index 9eb43ef289..69e109f1f7 100644 --- a/spec/features/projects/project_autocomplete_spec.rb +++ b/spec/features/projects/project_autocomplete_spec.rb @@ -60,7 +60,7 @@ describe 'Projects autocomplete page', type: :feature, js: true do ] names.map do |name| - identifier = name.gsub(/[ \-]+/, "-") + identifier = name.gsub(/[ \-]+/, "-").downcase FactoryGirl.create :project, name: name, identifier: identifier end From dea89b443607eab47b159c9eb96a65035706c836 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Sat, 14 Apr 2018 00:05:28 +0100 Subject: [PATCH 6/8] fixed typo --- spec/features/projects/project_autocomplete_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/projects/project_autocomplete_spec.rb b/spec/features/projects/project_autocomplete_spec.rb index 69e109f1f7..0dde5f900a 100644 --- a/spec/features/projects/project_autocomplete_spec.rb +++ b/spec/features/projects/project_autocomplete_spec.rb @@ -95,7 +95,7 @@ describe 'Projects autocomplete page', type: :feature, js: true do # find terms at the end of project names top_menu.search 'END' - with(top_menu.search_results) do + within(top_menu.search_results) do expect(page).to have_selector( '.ui-menu-item-wrapper', text: 'Very long project name with term at the END' From edd9529cc1090e9eeff6dbaade9f7f65ad19d7c3 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Mon, 16 Apr 2018 10:20:42 +0100 Subject: [PATCH 7/8] moved checks to fix spec --- .../projects/project_autocomplete_spec.rb | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/spec/features/projects/project_autocomplete_spec.rb b/spec/features/projects/project_autocomplete_spec.rb index 0dde5f900a..49eee4a647 100644 --- a/spec/features/projects/project_autocomplete_spec.rb +++ b/spec/features/projects/project_autocomplete_spec.rb @@ -93,23 +93,6 @@ describe 'Projects autocomplete page', type: :feature, js: true do expect(page).to have_no_selector('.ui-menu-item-wrapper', text: 'Plain other project') end - # find terms at the end of project names - top_menu.search 'END' - within(top_menu.search_results) do - expect(page).to have_selector( - '.ui-menu-item-wrapper', - text: 'Very long project name with term at the END' - ) - end - - # Find literal matches exclusively if present - top_menu.search 'INK15' - within(top_menu.search_results) do - expect(page).to have_selector('.ui-menu-item-wrapper', text: 'INK15 - Bar') - expect(page).to have_no_selector('.ui-menu-item-wrapper', text: 'INK14 - Foo') - expect(page).to have_no_selector('.ui-menu-item-wrapper', text: 'INK16 - Baz') - end - # Expect hierarchy top_menu.clear_search @@ -128,6 +111,23 @@ describe 'Projects autocomplete page', type: :feature, js: true do expect(page).to have_selector('.ui-menu-item-wrapper', text: 'Plain project') end + # find terms at the end of project names + top_menu.search 'END' + within(top_menu.search_results) do + expect(page).to have_selector( + '.ui-menu-item-wrapper', + text: 'Very long project name with term at the END' + ) + end + + # Find literal matches exclusively if present + top_menu.search 'INK15' + within(top_menu.search_results) do + expect(page).to have_selector('.ui-menu-item-wrapper', text: 'INK15 - Bar') + expect(page).to have_no_selector('.ui-menu-item-wrapper', text: 'INK14 - Foo') + expect(page).to have_no_selector('.ui-menu-item-wrapper', text: 'INK16 - Baz') + end + # Visit a project top_menu.search_and_select ' Date: Tue, 17 Apr 2018 10:24:17 +0100 Subject: [PATCH 8/8] fixed hierarchy check plain project is not supposed to be found when searching for "plain other project" while there is a perfect match --- spec/features/projects/project_autocomplete_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/features/projects/project_autocomplete_spec.rb b/spec/features/projects/project_autocomplete_spec.rb index 49eee4a647..0206cb499a 100644 --- a/spec/features/projects/project_autocomplete_spec.rb +++ b/spec/features/projects/project_autocomplete_spec.rb @@ -108,7 +108,6 @@ describe 'Projects autocomplete page', type: :feature, js: true do within(top_menu.search_results) do expect(page).to have_selector('.ui-state-disabled .ui-menu-item-wrapper', text: 'foobar') expect(page).to have_selector('.ui-menu-item-wrapper.ui-state-active', text: 'ยป Plain other project') - expect(page).to have_selector('.ui-menu-item-wrapper', text: 'Plain project') end # find terms at the end of project names