From d8cfa697c66dc87a0d5cf69fababcfabd7219ef5 Mon Sep 17 00:00:00 2001 From: Dylan Tientcheu Date: Tue, 22 Jul 2025 19:25:33 +0200 Subject: [PATCH] fix: cater for facetFilters --- pnpm-lock.yaml | 39 +++++++------------ .../components/VPAlgoliaSearchBox.vue | 34 +++++++++++++++- .../components/VPNavBarSearchButton.vue | 25 ++++-------- types/docsearch.d.ts | 6 +++ 4 files changed, 59 insertions(+), 45 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f445f9f2..c16ebe9d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -22,10 +22,10 @@ importers: dependencies: '@docsearch/css': specifier: ^4.0.0-beta - version: 4.0.0-beta.1 + version: 4.0.0-beta.4 '@docsearch/js': specifier: ^4.0.0-beta - version: 4.0.0-beta.1(@algolia/client-search@5.31.0)(zod@3.25.75) + version: 4.0.0-beta.4(@algolia/client-search@5.31.0)(zod@3.25.75) '@iconify-json/simple-icons': specifier: ^1.2.42 version: 1.2.42 @@ -373,12 +373,6 @@ packages: peerDependencies: search-insights: '>= 1 < 3' - '@algolia/autocomplete-preset-algolia@1.19.2': - resolution: {integrity: sha512-/Z9tDn84fnyUyjajvWRskOX7p/BDKK5PidEA4Y/aAl0c6VfHu5dMkTDG090CIiskLUgpkHacLbz+A10gMBP++Q==} - peerDependencies: - '@algolia/client-search': '>= 4.9.1 < 6' - algoliasearch: '>= 4.9.1 < 6' - '@algolia/autocomplete-shared@1.19.2': resolution: {integrity: sha512-jEazxZTVD2nLrC+wYlVHQgpBoBB5KPStrJxLzsIFl6Kqd1AlG9sIAGl39V5tECLpIQzB3Qa2T6ZPJ1ChkwMK/w==} peerDependencies: @@ -485,14 +479,14 @@ packages: conventional-commits-parser: optional: true - '@docsearch/css@4.0.0-beta.1': - resolution: {integrity: sha512-0gz3zy5ygHT048FRVcmk1i8XQhVye42In04FlknABzjpNOOBjfvlIuewIFJKDYoCh8Aq3+15Jy3akkb6bNBTxA==} + '@docsearch/css@4.0.0-beta.4': + resolution: {integrity: sha512-NSttNRAtL97ezeep+NtaoFN/TDDcm1Kx2Y42hxUEc3habkDS/rTLgDW+xn23ALFy3N5zHd/+VK5SN3XMcCVnVA==} - '@docsearch/js@4.0.0-beta.1': - resolution: {integrity: sha512-2nJNLAE5kr/YUNLXVADHcICia2/oQ0k3rDT85ozNeVrbaeIUB/1tA2AV8y27UPufwaK5zMl3UAR3lCueKds+6Q==} + '@docsearch/js@4.0.0-beta.4': + resolution: {integrity: sha512-vBQD+ZqZpYdpg02D+X8zvo6kwXNAWRZonb5g8Ie9L/NQIADInNoHLakDO0ZIntGqZmD8pZkw0hgjGKw8axQzFA==} - '@docsearch/react@4.0.0-beta.1': - resolution: {integrity: sha512-XPxHMzfD+FBEAkXPt0g64Mc06Q3plevAuIzQMnW6b5slVbVM8xH3Dmi0eXx9LLVVnV2mji6q2OKm/ET6QWxHVw==} + '@docsearch/react@4.0.0-beta.4': + resolution: {integrity: sha512-3kR8mtt15tUcgJncueRsNIsoUo6a5TXvqwZwKlRpU3OkmjMKFW2meXs0Dpvvdyv5TcEod94okKPyvBXVmNENrA==} peerDependencies: '@types/react': '>= 16.8.0 < 20.0.0' react: '>= 16.8.0 < 20.0.0' @@ -3527,12 +3521,6 @@ snapshots: - '@algolia/client-search' - algoliasearch - '@algolia/autocomplete-preset-algolia@1.19.2(@algolia/client-search@5.31.0)(algoliasearch@5.31.0)': - dependencies: - '@algolia/autocomplete-shared': 1.19.2(@algolia/client-search@5.31.0)(algoliasearch@5.31.0) - '@algolia/client-search': 5.31.0 - algoliasearch: 5.31.0 - '@algolia/autocomplete-shared@1.19.2(@algolia/client-search@5.31.0)(algoliasearch@5.31.0)': dependencies: '@algolia/client-search': 5.31.0 @@ -3665,11 +3653,11 @@ snapshots: conventional-commits-filter: 5.0.0 conventional-commits-parser: 6.2.0 - '@docsearch/css@4.0.0-beta.1': {} + '@docsearch/css@4.0.0-beta.4': {} - '@docsearch/js@4.0.0-beta.1(@algolia/client-search@5.31.0)(zod@3.25.75)': + '@docsearch/js@4.0.0-beta.4(@algolia/client-search@5.31.0)(zod@3.25.75)': dependencies: - '@docsearch/react': 4.0.0-beta.1(@algolia/client-search@5.31.0)(zod@3.25.75) + '@docsearch/react': 4.0.0-beta.4(@algolia/client-search@5.31.0)(zod@3.25.75) transitivePeerDependencies: - '@algolia/client-search' - '@types/react' @@ -3678,12 +3666,11 @@ snapshots: - search-insights - zod - '@docsearch/react@4.0.0-beta.1(@algolia/client-search@5.31.0)(zod@3.25.75)': + '@docsearch/react@4.0.0-beta.4(@algolia/client-search@5.31.0)(zod@3.25.75)': dependencies: '@ai-sdk/react': 1.2.12(zod@3.25.75) '@algolia/autocomplete-core': 1.19.2(@algolia/client-search@5.31.0)(algoliasearch@5.31.0) - '@algolia/autocomplete-preset-algolia': 1.19.2(@algolia/client-search@5.31.0)(algoliasearch@5.31.0) - '@docsearch/css': 4.0.0-beta.1 + '@docsearch/css': 4.0.0-beta.4 algoliasearch: 5.31.0 marked: 15.0.12 transitivePeerDependencies: diff --git a/src/client/theme-default/components/VPAlgoliaSearchBox.vue b/src/client/theme-default/components/VPAlgoliaSearchBox.vue index 003f5746..d8859559 100644 --- a/src/client/theme-default/components/VPAlgoliaSearchBox.vue +++ b/src/client/theme-default/components/VPAlgoliaSearchBox.vue @@ -31,12 +31,44 @@ async function update() { ).filter((f) => !f.startsWith('lang:')), `lang:${lang.value}` ] + + // Rebuild the askAi prop as an object + const askAiProp = (options as DefaultTheme.AlgoliaSearchOptions & { + askAi?: any + }).askAi + + const askAi = askAiProp + ? { + // If askAi prop is a string, treat it as the assistantId and use + // the default indexName, apiKey and appId from the main options. + // If it's an object, spread its explicit values. + indexName: + typeof askAiProp === 'string' + ? (options as DefaultTheme.AlgoliaSearchOptions).indexName + : askAiProp.indexName, + apiKey: + typeof askAiProp === 'string' + ? (options as DefaultTheme.AlgoliaSearchOptions).apiKey + : askAiProp.apiKey, + appId: + typeof askAiProp === 'string' + ? (options as DefaultTheme.AlgoliaSearchOptions).appId + : askAiProp.appId, + assistantId: + typeof askAiProp === 'string' ? askAiProp : askAiProp.assistantId, + // Re-use the merged facetFilters from the search parameters so that + // Ask AI uses the same language filtering as the regular search. + searchParameters: facetFilters.length ? { facetFilters } : undefined + } + : undefined + initialize({ ...options, searchParameters: { ...options.searchParameters, facetFilters - } + }, + askAi }) } diff --git a/src/client/theme-default/components/VPNavBarSearchButton.vue b/src/client/theme-default/components/VPNavBarSearchButton.vue index f94c4fc3..1e55ea0a 100644 --- a/src/client/theme-default/components/VPNavBarSearchButton.vue +++ b/src/client/theme-default/components/VPNavBarSearchButton.vue @@ -94,7 +94,7 @@ const translate = createSearchTranslate(defaultTranslations) @media (min-width: 768px) { .DocSearch-Button { - justify-content: flex-start; + justify-content: space-between; border: 1px solid transparent; border-radius: 8px; padding: 0 10px 0 12px; @@ -173,12 +173,11 @@ const translate = createSearchTranslate(defaultTranslations) .DocSearch-Button .DocSearch-Button-Key { display: block; - margin: 2px 0 0 0; border: 1px solid var(--vp-c-divider); /*rtl:begin:ignore*/ border-right: none; border-radius: 4px 0 0 4px; - padding-left: 4px; + padding: 0 1px; /*rtl:end:ignore*/ min-width: 0; width: auto; @@ -195,38 +194,28 @@ const translate = createSearchTranslate(defaultTranslations) border-right: 1px solid var(--vp-c-divider); border-left: none; border-radius: 0 4px 4px 0; - padding-left: 4px; - padding-right: 4px; color: var(--docsearch-muted-color); /*rtl:end:ignore*/ } +.DocSearch-Button-Key svg { + color: var(--docsearch-muted-color); +} + .DocSearch-Button .DocSearch-Button-Key:first-child { font-size: 0 !important; } -.DocSearch-Button .DocSearch-Button-Key:first-child:after { - content: 'Ctrl'; - font-size: 12px; - padding-right: 4px; - letter-spacing: normal; - color: var(--docsearch-muted-color); -} .DocSearch-Commands-Key { color: var(--vp-c-text-2); padding: 4px; border-radius: 4px; + line-height: 19px; border: 1px solid var(--vp-c-divider); } -.mac .DocSearch-Button .DocSearch-Button-Key:first-child:after { - content: '\2318'; -} -.DocSearch-Button .DocSearch-Button-Key:first-child > * { - display: none; -} .DocSearch-Search-Icon { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' stroke-width='1.6' viewBox='0 0 20 20'%3E%3Cpath fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' d='m14.386 14.386 4.088 4.088-4.088-4.088A7.533 7.533 0 1 1 3.733 3.733a7.533 7.533 0 0 1 10.653 10.653z'/%3E%3C/svg%3E"); diff --git a/types/docsearch.d.ts b/types/docsearch.d.ts index 4071d276..a09946e8 100644 --- a/types/docsearch.d.ts +++ b/types/docsearch.d.ts @@ -197,4 +197,10 @@ export interface DocSearchAskAi { * The assistant ID to use for the ask AI feature. */ assistantId: string | null + /** + * The search parameters to use for the ask AI feature. + */ + searchParameters?: { + facetFilters?: SearchOptions['facetFilters'] + } }