@@ -51,6 +51,11 @@ export type DocSearchAskAi = {
5151 } ;
5252} ;
5353
54+ export interface DocSearchIndex {
55+ name : string ;
56+ searchParameters ?: SearchParamsObject ;
57+ }
58+
5459export interface DocSearchProps {
5560 /**
5661 * Algolia application id used by the search client.
@@ -62,8 +67,16 @@ export interface DocSearchProps {
6267 apiKey : string ;
6368 /**
6469 * Name of the algolia index to query.
70+ *
71+ * @deprecated `indexName` will be removed in a future version. Please use `indices` property going forward.
72+ */
73+ indexName ?: string ;
74+ /**
75+ * List of indices and _optional_ searchParameters to be used for search.
76+ *
77+ * @see {@link https://docsearch.algolia.com/docs/api#indices }
6578 */
66- indexName : string ;
79+ indices ?: Array < DocSearchIndex | string > ;
6780 /**
6881 * Configuration or assistant id to enable ask ai mode. Pass a string assistant id or a full config object.
6982 */
@@ -78,6 +91,8 @@ export interface DocSearchProps {
7891 placeholder ?: string ;
7992 /**
8093 * Additional algolia search parameters to merge into each query.
94+ *
95+ * @deprecated `searchParameters` will be removed in a future version. Please use `indices` property going forward.
8196 */
8297 searchParameters ?: SearchParamsObject ;
8398 /**
@@ -142,7 +157,7 @@ export interface DocSearchProps {
142157 recentSearchesWithFavoritesLimit ?: number ;
143158}
144159
145- export function DocSearch ( { ...props } : DocSearchProps ) : JSX . Element {
160+ export function DocSearch ( { indexName , searchParameters , indices = [ ] , ...props } : DocSearchProps ) : JSX . Element {
146161 const searchButtonRef = React . useRef < HTMLButtonElement > ( null ) ;
147162 const [ isOpen , setIsOpen ] = React . useState ( false ) ;
148163 const [ initialQuery , setInitialQuery ] = React . useState < string | undefined > ( props ?. initialQuery || undefined ) ;
@@ -200,6 +215,26 @@ export function DocSearch({ ...props }: DocSearchProps): JSX.Element {
200215 } ) ;
201216 useTheme ( { theme : props . theme } ) ;
202217
218+ // Format the `indexes` to be used until `indexName` and `searchParameters` props are fully removed.
219+ const indexes : DocSearchIndex [ ] = [ ] ;
220+
221+ if ( indexName && indexName !== '' ) {
222+ indexes . push ( {
223+ name : indexName ,
224+ searchParameters,
225+ } ) ;
226+ }
227+
228+ if ( indices . length > 0 ) {
229+ indices . forEach ( ( index ) => {
230+ indexes . push ( typeof index === 'string' ? { name : index } : index ) ;
231+ } ) ;
232+ }
233+
234+ if ( indexes . length < 1 ) {
235+ throw new Error ( 'Must supply either `indexName` or `indices` for DocSearch to work' ) ;
236+ }
237+
203238 return (
204239 < >
205240 < DocSearchButton ref = { searchButtonRef } translations = { props ?. translations ?. button } onClick = { onOpen } />
@@ -214,6 +249,7 @@ export function DocSearch({ ...props }: DocSearchProps): JSX.Element {
214249 translations = { props ?. translations ?. modal }
215250 isAskAiActive = { isAskAiActive }
216251 canHandleAskAi = { canHandleAskAi }
252+ indexes = { indexes }
217253 onAskAiToggle = { onAskAiToggle }
218254 onClose = { onClose }
219255 /> ,
0 commit comments