Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repo sync #33069

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/search/scripts/index-elasticsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand All @@ -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]
})
Expand Down
2 changes: 2 additions & 0 deletions src/search/scripts/parse-page-sections-into-records.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand Down Expand Up @@ -91,5 +92,6 @@ export default function parsePageSectionsIntoRecords(page) {
headings,
content,
intro,
toplevel,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"content": "これは、ばかげた foo ワードのフィクスチャです。",
"topics": ["Test", "Fixture"],
"popularity": 0.5,
"intro": "イントロあり"
"intro": "イントロあり",
"toplevel": "Fooing"
},
"/ja/bar": {
"objectID": "/ja/bar",
Expand All @@ -17,7 +18,8 @@
"content": "bar も持っていない場合、foo を持つことはできません。",
"topics": ["Test", "Fixture", "Get started"],
"popularity": 0.6,
"intro": "イントロがない"
"intro": "イントロがない",
"toplevel": "Baring"
},
"/ja/breadcrumbless": {
"objectID": "/ja/bar",
Expand All @@ -27,6 +29,7 @@
"content": "すべてのページにブレッドクラムがあるわけではありません。人生の事実。",
"topics": [],
"popularity": 0.1,
"intro": ""
"intro": "",
"toplevel": "Baring"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"headings": "",
"content": "これは、ばかげた foo ワードのフィクスチャです。 GHAE専用。",
"topics": ["Test", "Fixture"],
"intro": "サンプル紹介"
"intro": "サンプル紹介",
"toplevel": "Fooing"
}
}
3 changes: 3 additions & 0 deletions src/search/tests/parse-page-sections-into-records.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading