From 75553ac1bb1b7353691220d23df2a5b648e18ff2 Mon Sep 17 00:00:00 2001 From: Brian Rinaldi Date: Fri, 7 Nov 2025 08:18:05 -0500 Subject: [PATCH 1/2] Add filters for custom search result sorting The search results have been designed to prioritize AWS by default in the crawler via a recent change, but this update forces the results to prioritize AWS when you are in /aws and Snowflake when you are in /snowflake, helping users get the results most relevant to where they are. --- astro.config.mjs | 7 +------ src/config/docsearch.ts | 46 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 src/config/docsearch.ts diff --git a/astro.config.mjs b/astro.config.mjs index 0580c7b9..89a16158 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -198,12 +198,7 @@ export default defineConfig({ }, }), starlightDocSearch({ - appId: 'XBW1JU7CW5', - apiKey: '6b0341e2f50196d328d088dbb5cd6166', - indexName: 'localstack', - searchParameters: { - facets: ['lvl0'], - }, + clientOptionsModule: './src/config/docsearch.ts', }), ], sidebar: [ diff --git a/src/config/docsearch.ts b/src/config/docsearch.ts new file mode 100644 index 00000000..eba54af0 --- /dev/null +++ b/src/config/docsearch.ts @@ -0,0 +1,46 @@ +import type { DocSearchClientOptions } from '@astrojs/starlight-docsearch'; + +export default { + appId: 'XBW1JU7CW5', + apiKey: '6b0341e2f50196d328d088dbb5cd6166', + indexName: 'localstack', + searchParameters: { + facets: ['lvl0'], + }, + transformSearchClient(searchClient) { + return { + ...searchClient, + search(requests: any) { + // Get the current pathname at runtime + const pathname = typeof window !== 'undefined' ? window.location.pathname : ''; + + // Determine the boost filter based on pathname + let boostFilter: string | null = null; + if (pathname.startsWith('/aws/')) { + boostFilter = "hierarchy.lvl0:'LocalStack for AWS'"; + } else if (pathname.startsWith('/snowflake/')) { + boostFilter = "hierarchy.lvl0:LocalStack for Snowflake"; + } + + if (!boostFilter) { + return searchClient.search(requests); + } + + if (!requests || typeof requests !== 'object' || !Array.isArray(requests.requests)) { + return searchClient.search(requests); + } + + const transformedRequests = { + ...requests, + requests: requests.requests.map((request: any) => ({ + ...request, + optionalFilters: [boostFilter], + sumOrFiltersScores: true, + })), + }; + + return searchClient.search(transformedRequests); + }, + }; + }, +} satisfies DocSearchClientOptions; \ No newline at end of file From c75363bb2512117bfc4383d151f4ca0d4284d666 Mon Sep 17 00:00:00 2001 From: Brian Rinaldi Date: Fri, 7 Nov 2025 08:21:44 -0500 Subject: [PATCH 2/2] Update docsearch.ts --- src/config/docsearch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/docsearch.ts b/src/config/docsearch.ts index eba54af0..f93ee99e 100644 --- a/src/config/docsearch.ts +++ b/src/config/docsearch.ts @@ -17,7 +17,7 @@ export default { // Determine the boost filter based on pathname let boostFilter: string | null = null; if (pathname.startsWith('/aws/')) { - boostFilter = "hierarchy.lvl0:'LocalStack for AWS'"; + boostFilter = "hierarchy.lvl0:LocalStack for AWS"; } else if (pathname.startsWith('/snowflake/')) { boostFilter = "hierarchy.lvl0:LocalStack for Snowflake"; }