11/* eslint-disable no-underscore-dangle */
22/* eslint-disable @typescript-eslint/naming-convention */
3+ import type { SearchParamsObject } from 'algoliasearch' ;
34import type { PropType } from 'vue' ;
45import {
56 computed , defineComponent , h , onMounted , ref , watch ,
@@ -18,6 +19,8 @@ import {
1819 preconnectToAlgolia ,
1920} from '../utils/index.js' ;
2021
22+ import { getDocVersion } from '../../../../utils/version.js' ;
23+
2124declare const __DOCSEARCH_INJECT_STYLES__ : boolean ;
2225const defaultBranch = 'latest' ;
2326
@@ -50,26 +53,14 @@ export const Docsearch = defineComponent({
5053 const hasInitialized = ref ( false ) ;
5154 const hasTriggered = ref ( false ) ;
5255
53- const getDocVersion = ( branch = 'latest' , path = '' ) => {
54- if ( path . indexOf ( 'UserGuide/Master' ) > - 1 || path . indexOf ( 'UserGuide' ) === - 1 ) {
55- return branch ;
56- }
57- const branchRex = / U s e r G u i d e \/ V ( \d + \. \d + \. x ) / ;
58- if ( branchRex . test ( path ) ) {
59- const tag = branchRex . exec ( path ) ! [ 1 ] ;
60- return `rel/${ tag . replace ( '.x' , '' ) } ` ;
61- }
62- return branch ;
63- } ;
64-
6556 const version = computed ( ( ) => getDocVersion ( defaultBranch , pageData . value . path ) ) ;
6657 // resolve docsearch options for current locale
6758 const options = computed ( ( ) => {
68- const { locales = { } , ...options } = props . options ;
59+ const { locales = { } , ...rest } = props . options ;
6960
7061 return {
7162 ...docSearchOptions . value ,
72- ...options ,
63+ ...rest ,
7364 ...locales [ routeLocale . value ] ,
7465 } ;
7566 } ) ;
@@ -79,14 +70,17 @@ export const Docsearch = defineComponent({
7970 */
8071 const initialize = async ( ) : Promise < void > => {
8172 const { default : docsearch } = await import ( '@docsearch/js' ) ;
73+
74+ const { indexName, searchParameters } = options . value ;
8275 docsearch ( {
8376 ...docsearchShim ,
8477 ...options . value ,
8578 container : `#${ props . containerId } ` ,
8679 searchParameters : {
87- ...options . value . searchParameters ,
80+ ...searchParameters ,
81+ indexName,
8882 facetFilters : getFacetFilters (
89- options . value . searchParameters ?. facetFilters ,
83+ ( searchParameters as SearchParamsObject | undefined ) ?. facetFilters ,
9084 lang . value ,
9185 version . value ,
9286 ) ,
0 commit comments