diff --git a/aio/src/app/search/search-results/search-results.component.spec.ts b/aio/src/app/search/search-results/search-results.component.spec.ts index a677d1b317..3ecc276de8 100644 --- a/aio/src/app/search/search-results/search-results.component.spec.ts +++ b/aio/src/app/search/search-results/search-results.component.spec.ts @@ -69,6 +69,19 @@ describe('SearchResultsComponent', () => { ]); }); + it('should special case results that are top level folders', () => { + searchResults.next({ query: '', results: [ + { path: 'tutorial', title: 'Tutorial index', type: '', keywords: '', titleWords: '' }, + { path: 'tutorial/toh-pt1', title: 'Tutorial - part 1', type: '', keywords: '', titleWords: '' }, + ]}); + expect(currentAreas).toEqual([ + { name: 'tutorial', pages: [ + { path: 'tutorial/toh-pt1', title: 'Tutorial - part 1', type: '', keywords: '', titleWords: '' }, + { path: 'tutorial', title: 'Tutorial index', type: '', keywords: '', titleWords: '' }, + ], priorityPages: [] } + ]); + }); + it('should sort by title within sorted area', () => { const results = getTestResults(5); searchResults.next({ query: '', results: results }); diff --git a/aio/src/app/search/search-results/search-results.component.ts b/aio/src/app/search/search-results/search-results.component.ts index 86423c3a98..b5e4fabaa2 100644 --- a/aio/src/app/search/search-results/search-results.component.ts +++ b/aio/src/app/search/search-results/search-results.component.ts @@ -20,6 +20,7 @@ export interface SearchArea { export class SearchResultsComponent implements OnInit { readonly defaultArea = 'other'; + readonly topLevelFolders = ['guide', 'tutorial']; notFound = false; @@ -76,6 +77,9 @@ export class SearchResultsComponent implements OnInit { // 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; }