diff --git a/aio/src/app/shared/search-results/search-results.component.spec.ts b/aio/src/app/shared/search-results/search-results.component.spec.ts index 2dab9018af..af32de5b88 100644 --- a/aio/src/app/shared/search-results/search-results.component.spec.ts +++ b/aio/src/app/shared/search-results/search-results.component.spec.ts @@ -71,23 +71,33 @@ describe('SearchResultsComponent', () => { }); it('should map the search results into groups based on their containing folder', () => { - setSearchResults('', [guideA, apiD, guideB]); + const startA = { path: 'start/a', title: 'Start A', deprecated: false, keywords: '', titleWords: '', type: '', topics: '' }; + const tutorialA = { path: 'tutorial/a', title: 'Tutorial A', deprecated: false, keywords: '', titleWords: '', type: '', topics: '' }; + + setSearchResults('', [guideA, apiD, guideB, startA, tutorialA]); expect(component.searchAreas).toEqual([ { name: 'api', priorityPages: [apiD], pages: [] }, - { name: 'guide', priorityPages: [guideA, guideB], pages: [] } + { name: 'guides', priorityPages: [guideA, guideB], pages: [] }, + { name: 'tutorials', priorityPages: [startA, tutorialA], pages: [] }, ]); }); it('should special case results that are top level folders', () => { setSearchResults('', [ + { path: 'docs', title: 'Docs introduction', type: '', keywords: '', titleWords: '', deprecated: false, topics: '' }, + { path: 'start', title: 'Getting started', type: '', keywords: '', titleWords: '', deprecated: false, topics: '' }, { path: 'tutorial', title: 'Tutorial index', type: '', keywords: '', titleWords: '', deprecated: false, topics: '' }, { path: 'tutorial/toh-pt1', title: 'Tutorial - part 1', type: '', keywords: '', titleWords: '', deprecated: false, topics: '' }, ]); expect(component.searchAreas).toEqual([ - { name: 'tutorial', priorityPages: [ + { name: 'guides', priorityPages: [ + { path: 'docs', title: 'Docs introduction', type: '', keywords: '', titleWords: '', deprecated: false, topics: '' }, + ], pages: [] }, + { name: 'tutorials', priorityPages: [ + { path: 'start', title: 'Getting started', type: '', keywords: '', titleWords: '', deprecated: false, topics: '' }, { path: 'tutorial', title: 'Tutorial index', type: '', keywords: '', titleWords: '', deprecated: false, topics: '' }, { path: 'tutorial/toh-pt1', title: 'Tutorial - part 1', type: '', keywords: '', titleWords: '', deprecated: false, topics: '' }, - ], pages: [] } + ], pages: [] }, ]); }); diff --git a/aio/src/app/shared/search-results/search-results.component.ts b/aio/src/app/shared/search-results/search-results.component.ts index 6d253bc7cc..3d92d5cd94 100644 --- a/aio/src/app/shared/search-results/search-results.component.ts +++ b/aio/src/app/shared/search-results/search-results.component.ts @@ -28,9 +28,17 @@ export class SearchResultsComponent implements OnChanges { @Output() resultSelected = new EventEmitter(); - readonly defaultArea = 'other'; searchState: SearchState = SearchState.InProgress; - readonly topLevelFolders = ['api', 'cli', 'errors', 'guide', 'start', 'tutorial']; + readonly defaultArea = 'other'; + readonly folderToAreaMap: Record = { + api: 'api', + cli: 'cli', + docs: 'guides', + errors: 'errors', + guide: 'guides', + start: 'tutorials', + tutorial: 'tutorials', + }; searchAreas: SearchArea[] = []; ngOnChanges() { @@ -59,7 +67,7 @@ export class SearchResultsComponent implements OnChanges { const searchAreaMap: { [key: string]: SearchResult[] } = {}; search.results.forEach(result => { if (!result.title) { return; } // bad data; should fix - const areaName = this.computeAreaName(result) || this.defaultArea; + const areaName = this.computeAreaName(result); const area = searchAreaMap[areaName] = searchAreaMap[areaName] || []; area.push(result); }); @@ -75,12 +83,9 @@ export class SearchResultsComponent implements OnChanges { } // Split the search result path and use the top level folder, if there is one, as the area name. - private computeAreaName(result: SearchResult) { - if (this.topLevelFolders.indexOf(result.path) !== -1) { - return result.path; - } - const [areaName, rest] = result.path.split('/', 2); - return rest && areaName; + private computeAreaName(result: SearchResult): string { + const [folder] = result.path.split('/', 1); + return this.folderToAreaMap[folder] ?? this.defaultArea; } }