feat(v4): Add support for multi-index search#2736
Conversation
✅ Deploy Preview for docsearch ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| // Format the `indexes` to be used until `indexName` and `searchParameters` props are fully removed. | ||
| const indexes: DocSearchIndex[] = []; | ||
|
|
||
| if (indexName && indexName !== '') { | ||
| indexes.push({ | ||
| name: indexName, | ||
| searchParameters, | ||
| }); | ||
| } | ||
|
|
||
| if (indices.length > 0) { | ||
| indices.forEach((index) => { | ||
| indexes.push(typeof index === 'string' ? { name: index } : index); | ||
| }); | ||
| } | ||
|
|
||
| if (indexes.length < 1) { | ||
| throw new Error('Must supply either `indexName` or `indices` for DocSearch to work'); | ||
| } |
There was a problem hiding this comment.
From what I understand, this fallback logic only applies when using <DocSearch>, but it doesn't apply when using <DocSearchButton> and <DocSearchModal> directly, like Docusaurus does.
Unfortunately, this PR broke the DocSearch v3/v4 retrocompatibility we expected for Docusaurus, and upgrading from beta8 to GA makes the search unusable: facebook/docusaurus#11327
| translations={props?.translations?.modal} | ||
| isAskAiActive={isAskAiActive} | ||
| canHandleAskAi={canHandleAskAi} | ||
| indexes={indexes} |
There was a problem hiding this comment.
Why is DocSearch prop named indices, while subcomponents accept an indexes prop? Isn't that a typo? Why not always a consistent name?
| describe('Indexes', () => { | ||
| it('renders with deprecated indexName prop', () => { | ||
| expect(() => <DocSearch indexName="My test Index" />).not.toThrowError(); | ||
| }); | ||
|
|
||
| it('renders with new indices prop', () => { | ||
| expect(() => render(<DocSearch indexName={undefined} indices={[{ name: 'testing' }]} />)).not.toThrowError(); | ||
| }); | ||
|
|
||
| it('throws an error if indexName or indices are not provided', () => { | ||
| expect(() => render(<DocSearch indexName={undefined} indices={[]} />)).toThrowError(); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Those tests only cover the root API, but do not cover <DocSearchButton> and <DocSearchModal> APIs
What
Adds support for multi-index search during keyword search. This does not impact AskAI in any way.
indicesproperty to accept a list of indexes for searchindexNameandsearchParameterspropertiesindexNameandsearchParametersare fully removedDocs
indicesand deprecation warnings forindexNameandsearchParametersrespectPrefersColorSchemewithin Docusaurus configDependencies