Skip to content

Commit 757bef6

Browse files
authored
feat: Improve algolia search results (#10948)
1 parent b52eca8 commit 757bef6

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,7 @@ public/page-data
9595
tsconfig.tsbuildinfo
9696

9797
public/mdx-images/*
98+
99+
# yalc
100+
.yalc
101+
yalc.lock

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"@radix-ui/react-tabs": "^1.0.4",
5858
"@radix-ui/react-toolbar": "^1.0.4",
5959
"@radix-ui/themes": "^2.0.3",
60-
"@sentry-internal/global-search": "^1.0.0",
60+
"@sentry-internal/global-search": "^1.1.0",
6161
"@sentry/nextjs": "8.20.0",
6262
"@types/mdx": "^2.0.9",
6363
"algoliasearch": "^4.23.3",

scripts/algolia.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323
import fs from 'fs';
2424
import {join} from 'path';
2525

26-
import {extrapolate, htmlToAlgoliaRecord} from '@sentry-internal/global-search';
26+
import {
27+
extrapolate,
28+
htmlToAlgoliaRecord,
29+
sentryAlgoliaIndexSettings,
30+
standardSDKSlug,
31+
} from '@sentry-internal/global-search';
2732
import algoliasearch, {SearchIndex} from 'algoliasearch';
2833

2934
import {isDeveloperDocs} from 'sentry-docs/isDeveloperDocs';
@@ -90,6 +95,12 @@ async function indexAndUpload() {
9095
deleteResult.objectIDs.length,
9196
DOCS_INDEX_NAME
9297
);
98+
99+
if (!isDeveloperDocs) {
100+
console.log('🔥 Applying custom index settings ...');
101+
await index.setSettings(sentryAlgoliaIndexSettings);
102+
console.log(`🔥 Applied custom settings to ${DOCS_INDEX_NAME}`);
103+
}
93104
}
94105

95106
async function fetchExistingRecordIds(algoliaIndex: SearchIndex) {
@@ -121,6 +132,17 @@ async function generateAlogliaRecords(pageFrontMatters: FrontMatter[]) {
121132
async function getRecords(pageFm: FrontMatter) {
122133
console.log('processing:', pageFm.slug);
123134

135+
let sdk: string | undefined;
136+
let framework: string | undefined;
137+
if (pageFm.slug.includes('platforms/')) {
138+
sdk = standardSDKSlug(pageFm.slug.split('/')[1])?.slug as string;
139+
framework = sdk;
140+
141+
if (pageFm.slug.includes('/guides/')) {
142+
framework = standardSDKSlug(pageFm.slug.split('/')[3])?.slug as string;
143+
}
144+
}
145+
124146
try {
125147
const htmlFile = join(staticHtmlFilesPath, pageFm.slug + '.html');
126148
const html = fs.readFileSync(htmlFile).toString();
@@ -131,6 +153,8 @@ async function getRecords(pageFm: FrontMatter) {
131153
url: '/' + pageFm.slug + '/',
132154
pathSegments: extrapolate(pageFm.slug, '/').map(x => `/${x}/`),
133155
keywords: pageFm.keywords,
156+
sdk,
157+
framework,
134158
},
135159
'#main'
136160
);

src/components/docPage/index.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ export function DocPage({
4141

4242
const pathname = serverContext().path.join('/');
4343

44-
const searchPlatforms = [currentPlatform?.name, currentGuide?.platform].filter(
45-
isTruthy
46-
);
44+
const searchPlatforms = [currentPlatform?.name, currentGuide?.name].filter(isTruthy);
4745

4846
const leafNode = nodeForPath(rootNode, path);
4947

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -2639,10 +2639,10 @@
26392639
"@sentry/types" "8.20.0"
26402640
"@sentry/utils" "8.20.0"
26412641

2642-
"@sentry-internal/global-search@^1.0.0":
2643-
version "1.0.0"
2644-
resolved "https://registry.npmjs.org/@sentry-internal/global-search/-/global-search-1.0.0.tgz"
2645-
integrity sha512-u4UUwxinDhUJ0kA4xGGQTr3QGJAWh7GRdFls9ys8coV7WjPNYt91MHfOWVdFzgeU6f4aO7RKE8uxSb/fkZiagQ==
2642+
"@sentry-internal/global-search@^1.1.0":
2643+
version "1.1.0"
2644+
resolved "https://registry.yarnpkg.com/@sentry-internal/global-search/-/global-search-1.1.0.tgz#108f11149a2516ea96b8a544fb4f8a0c046288e2"
2645+
integrity sha512-PL2oGOxr0vdnfPwVczs7VuV8bKhypbi1yN13gAT42AxgaSk3joBWzlEzLo7SXK53zBTWVyM2SAyBDzHWXEerJg==
26462646
dependencies:
26472647
"@types/react" ">=16"
26482648
"@types/react-dom" ">=16"

0 commit comments

Comments
 (0)