Skip to content

Commit 642d69e

Browse files
authored
Merge pull request #33069 from github/repo-sync
Repo sync
2 parents 65a2dba + 4ca697c commit 642d69e

File tree

7 files changed

+29
-10
lines changed

7 files changed

+29
-10
lines changed

src/search/scripts/index-elasticsearch.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ async function indexVersion(client, indexName, version, language, sourceDirector
381381
breadcrumbs: { type: 'text' },
382382
popularity: { type: 'float' },
383383
intro: { type: 'text' },
384+
// Use 'keyword' because it's faster to index and (more importantly)
385+
// faster to search on. It would be different if it was something
386+
// users could type in into a text input.
387+
toplevel: { type: 'keyword' },
384388
},
385389
},
386390
settings,
@@ -389,7 +393,7 @@ async function indexVersion(client, indexName, version, language, sourceDirector
389393
// POPULATE
390394
const allRecords = Object.values(records).sort((a, b) => b.popularity - a.popularity)
391395
const operations = allRecords.flatMap((doc) => {
392-
const { title, objectID, content, breadcrumbs, headings, intro } = doc
396+
const { title, objectID, content, breadcrumbs, headings, intro, toplevel } = doc
393397
const contentEscaped = escapeHTML(content)
394398
const headingsEscaped = escapeHTML(headings)
395399
const record = {
@@ -408,6 +412,7 @@ async function indexVersion(client, indexName, version, language, sourceDirector
408412
// you never get a product of 0.0.
409413
popularity: doc.popularity + 1,
410414
intro,
415+
toplevel,
411416
}
412417
return [{ index: { _index: thisAlias } }, record]
413418
})

src/search/scripts/parse-page-sections-into-records.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default function parsePageSectionsIntoRecords(page) {
3838
.slice(0, breadcrumbsArray.length > 1 ? -1 : breadcrumbsArray.length)
3939
.join(' / ') || ''
4040

41+
const toplevel = breadcrumbsArray[0] || ''
4142
const objectID = href
4243

4344
const rootSelector = '[data-search=article-body]'
@@ -91,5 +92,6 @@ export default function parsePageSectionsIntoRecords(page) {
9192
headings,
9293
content,
9394
intro,
95+
toplevel,
9496
}
9597
}

src/search/tests/fixtures/search-indexes/github-docs-dotcom-en-records.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"content": "This is a fixture with the silly foo word.",
88
"topics": ["Test", "Fixture"],
99
"popularity": 0.5,
10-
"intro": "Has an intro"
10+
"intro": "Has an intro",
11+
"toplevel": "Fooing"
1112
},
1213
"/en/bar": {
1314
"objectID": "/en/bar",
@@ -17,7 +18,8 @@
1718
"content": "Can't have foo if you don't also have bar.",
1819
"topics": ["Test", "Fixture", "Get started"],
1920
"popularity": 0.6,
20-
"intro": "Has no intro"
21+
"intro": "Has no intro",
22+
"toplevel": "Baring"
2123
},
2224
"/en/breadcrumbless": {
2325
"objectID": "/en/bar",
@@ -27,7 +29,8 @@
2729
"content": "Not all pages have a breadcrumb. Fact of life.",
2830
"topics": [],
2931
"popularity": 0.1,
30-
"intro": ""
32+
"intro": "",
33+
"toplevel": "Baring"
3134
},
3235
"/en/get-started/foo/for-playwright": {
3336
"objectID": "/en/get-started/foo/for-playwright",
@@ -36,6 +39,7 @@
3639
"headings": "Opening",
3740
"content": "This page exists to serve a Playwright test to view an article page",
3841
"popularity": 0.5,
39-
"intro": "Exists for a Playwright test"
42+
"intro": "Exists for a Playwright test",
43+
"toplevel": "Fooing"
4044
}
4145
}

src/search/tests/fixtures/search-indexes/github-docs-dotcom-ja-records.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"content": "これは、ばかげた foo ワードのフィクスチャです。",
88
"topics": ["Test", "Fixture"],
99
"popularity": 0.5,
10-
"intro": "イントロあり"
10+
"intro": "イントロあり",
11+
"toplevel": "Fooing"
1112
},
1213
"/ja/bar": {
1314
"objectID": "/ja/bar",
@@ -17,7 +18,8 @@
1718
"content": "bar も持っていない場合、foo を持つことはできません。",
1819
"topics": ["Test", "Fixture", "Get started"],
1920
"popularity": 0.6,
20-
"intro": "イントロがない"
21+
"intro": "イントロがない",
22+
"toplevel": "Baring"
2123
},
2224
"/ja/breadcrumbless": {
2325
"objectID": "/ja/bar",
@@ -27,6 +29,7 @@
2729
"content": "すべてのページにブレッドクラムがあるわけではありません。人生の事実。",
2830
"topics": [],
2931
"popularity": 0.1,
30-
"intro": ""
32+
"intro": "",
33+
"toplevel": "Baring"
3134
}
3235
}

src/search/tests/fixtures/search-indexes/github-docs-ghec-en-records.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"headings": "",
77
"content": "This is a fixture with the silly foo word. Exclusively for GHEC.",
88
"topics": ["Test", "Fixture"],
9-
"intro": "Sample intro"
9+
"intro": "Sample intro",
10+
"toplevel": "Fooing"
1011
}
1112
}

src/search/tests/fixtures/search-indexes/github-docs-ghec-ja-records.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"headings": "",
77
"content": "これは、ばかげた foo ワードのフィクスチャです。 GHAE専用。",
88
"topics": ["Test", "Fixture"],
9-
"intro": "サンプル紹介"
9+
"intro": "サンプル紹介",
10+
"toplevel": "Fooing"
1011
}
1112
}

src/search/tests/parse-page-sections-into-records.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe('search parsePageSectionsIntoRecords module', () => {
5151
'Bullet\nPoint\nNumbered\nList\n' +
5252
"Further reading\nThis won't be ignored.",
5353
intro: 'This is an introduction to the article.',
54+
toplevel: 'GitHub Actions',
5455
}
5556

5657
expect(record).toEqual(expected)
@@ -68,6 +69,7 @@ describe('search parsePageSectionsIntoRecords module', () => {
6869
headings: '',
6970
content: 'This is an introduction to the article.\nFirst paragraph.\nSecond paragraph.',
7071
intro: 'This is an introduction to the article.',
72+
toplevel: 'Education',
7173
}
7274

7375
expect(record).toEqual(expected)
@@ -85,6 +87,7 @@ describe('search parsePageSectionsIntoRecords module', () => {
8587
headings: '',
8688
content: 'This is an introduction to the article.',
8789
intro: 'This is an introduction to the article.',
90+
toplevel: 'Education',
8891
}
8992

9093
expect(record).toEqual(expected)

0 commit comments

Comments
 (0)