diff --git a/src/search/scripts/index-elasticsearch.js b/src/search/scripts/index-elasticsearch.js index 9062c2809d91..ac78d312bd7a 100755 --- a/src/search/scripts/index-elasticsearch.js +++ b/src/search/scripts/index-elasticsearch.js @@ -381,6 +381,10 @@ async function indexVersion(client, indexName, version, language, sourceDirector breadcrumbs: { type: 'text' }, popularity: { type: 'float' }, intro: { type: 'text' }, + // Use 'keyword' because it's faster to index and (more importantly) + // faster to search on. It would be different if it was something + // users could type in into a text input. + toplevel: { type: 'keyword' }, }, }, settings, @@ -389,7 +393,7 @@ async function indexVersion(client, indexName, version, language, sourceDirector // POPULATE const allRecords = Object.values(records).sort((a, b) => b.popularity - a.popularity) const operations = allRecords.flatMap((doc) => { - const { title, objectID, content, breadcrumbs, headings, intro } = doc + const { title, objectID, content, breadcrumbs, headings, intro, toplevel } = doc const contentEscaped = escapeHTML(content) const headingsEscaped = escapeHTML(headings) const record = { @@ -408,6 +412,7 @@ async function indexVersion(client, indexName, version, language, sourceDirector // you never get a product of 0.0. popularity: doc.popularity + 1, intro, + toplevel, } return [{ index: { _index: thisAlias } }, record] }) diff --git a/src/search/scripts/parse-page-sections-into-records.js b/src/search/scripts/parse-page-sections-into-records.js index a25b280a22b4..0897b7c289a5 100644 --- a/src/search/scripts/parse-page-sections-into-records.js +++ b/src/search/scripts/parse-page-sections-into-records.js @@ -38,6 +38,7 @@ export default function parsePageSectionsIntoRecords(page) { .slice(0, breadcrumbsArray.length > 1 ? -1 : breadcrumbsArray.length) .join(' / ') || '' + const toplevel = breadcrumbsArray[0] || '' const objectID = href const rootSelector = '[data-search=article-body]' @@ -91,5 +92,6 @@ export default function parsePageSectionsIntoRecords(page) { headings, content, intro, + toplevel, } } diff --git a/src/search/tests/fixtures/search-indexes/github-docs-dotcom-en-records.json b/src/search/tests/fixtures/search-indexes/github-docs-dotcom-en-records.json index 6bdc7eba40e7..a961de890e3c 100644 --- a/src/search/tests/fixtures/search-indexes/github-docs-dotcom-en-records.json +++ b/src/search/tests/fixtures/search-indexes/github-docs-dotcom-en-records.json @@ -7,7 +7,8 @@ "content": "This is a fixture with the silly foo word.", "topics": ["Test", "Fixture"], "popularity": 0.5, - "intro": "Has an intro" + "intro": "Has an intro", + "toplevel": "Fooing" }, "/en/bar": { "objectID": "/en/bar", @@ -17,7 +18,8 @@ "content": "Can't have foo if you don't also have bar.", "topics": ["Test", "Fixture", "Get started"], "popularity": 0.6, - "intro": "Has no intro" + "intro": "Has no intro", + "toplevel": "Baring" }, "/en/breadcrumbless": { "objectID": "/en/bar", @@ -27,7 +29,8 @@ "content": "Not all pages have a breadcrumb. Fact of life.", "topics": [], "popularity": 0.1, - "intro": "" + "intro": "", + "toplevel": "Baring" }, "/en/get-started/foo/for-playwright": { "objectID": "/en/get-started/foo/for-playwright", @@ -36,6 +39,7 @@ "headings": "Opening", "content": "This page exists to serve a Playwright test to view an article page", "popularity": 0.5, - "intro": "Exists for a Playwright test" + "intro": "Exists for a Playwright test", + "toplevel": "Fooing" } } diff --git a/src/search/tests/fixtures/search-indexes/github-docs-dotcom-ja-records.json b/src/search/tests/fixtures/search-indexes/github-docs-dotcom-ja-records.json index 022e275d4e70..47a04af7dfbd 100644 --- a/src/search/tests/fixtures/search-indexes/github-docs-dotcom-ja-records.json +++ b/src/search/tests/fixtures/search-indexes/github-docs-dotcom-ja-records.json @@ -7,7 +7,8 @@ "content": "これは、ばかげた foo ワードのフィクスチャです。", "topics": ["Test", "Fixture"], "popularity": 0.5, - "intro": "イントロあり" + "intro": "イントロあり", + "toplevel": "Fooing" }, "/ja/bar": { "objectID": "/ja/bar", @@ -17,7 +18,8 @@ "content": "bar も持っていない場合、foo を持つことはできません。", "topics": ["Test", "Fixture", "Get started"], "popularity": 0.6, - "intro": "イントロがない" + "intro": "イントロがない", + "toplevel": "Baring" }, "/ja/breadcrumbless": { "objectID": "/ja/bar", @@ -27,6 +29,7 @@ "content": "すべてのページにブレッドクラムがあるわけではありません。人生の事実。", "topics": [], "popularity": 0.1, - "intro": "" + "intro": "", + "toplevel": "Baring" } } diff --git a/src/search/tests/fixtures/search-indexes/github-docs-ghec-en-records.json b/src/search/tests/fixtures/search-indexes/github-docs-ghec-en-records.json index 4c3e9cfc32a9..c3d0b76a09c9 100644 --- a/src/search/tests/fixtures/search-indexes/github-docs-ghec-en-records.json +++ b/src/search/tests/fixtures/search-indexes/github-docs-ghec-en-records.json @@ -6,6 +6,7 @@ "headings": "", "content": "This is a fixture with the silly foo word. Exclusively for GHEC.", "topics": ["Test", "Fixture"], - "intro": "Sample intro" + "intro": "Sample intro", + "toplevel": "Fooing" } } diff --git a/src/search/tests/fixtures/search-indexes/github-docs-ghec-ja-records.json b/src/search/tests/fixtures/search-indexes/github-docs-ghec-ja-records.json index 8bca0aefe2b9..813494dca645 100644 --- a/src/search/tests/fixtures/search-indexes/github-docs-ghec-ja-records.json +++ b/src/search/tests/fixtures/search-indexes/github-docs-ghec-ja-records.json @@ -6,6 +6,7 @@ "headings": "", "content": "これは、ばかげた foo ワードのフィクスチャです。 GHAE専用。", "topics": ["Test", "Fixture"], - "intro": "サンプル紹介" + "intro": "サンプル紹介", + "toplevel": "Fooing" } } diff --git a/src/search/tests/parse-page-sections-into-records.js b/src/search/tests/parse-page-sections-into-records.js index 84f2853577a1..c6811f3e671f 100644 --- a/src/search/tests/parse-page-sections-into-records.js +++ b/src/search/tests/parse-page-sections-into-records.js @@ -51,6 +51,7 @@ describe('search parsePageSectionsIntoRecords module', () => { 'Bullet\nPoint\nNumbered\nList\n' + "Further reading\nThis won't be ignored.", intro: 'This is an introduction to the article.', + toplevel: 'GitHub Actions', } expect(record).toEqual(expected) @@ -68,6 +69,7 @@ describe('search parsePageSectionsIntoRecords module', () => { headings: '', content: 'This is an introduction to the article.\nFirst paragraph.\nSecond paragraph.', intro: 'This is an introduction to the article.', + toplevel: 'Education', } expect(record).toEqual(expected) @@ -85,6 +87,7 @@ describe('search parsePageSectionsIntoRecords module', () => { headings: '', content: 'This is an introduction to the article.', intro: 'This is an introduction to the article.', + toplevel: 'Education', } expect(record).toEqual(expected)