API Reference
- JavaScript
- React
containerโ
type: string | HTMLElement| required
The container for the DocSearch search box. You can either pass a CSS selector or an Element. If there are several containers matching the selector, DocSearch picks up the first one.
environmentโ
type: typeof window|default: window| optional
The environment in which your application is running.
This is useful if youโre using DocSearch in a different context than window.
appIdโ
type: string| required
Your Algolia application ID.
apiKeyโ
type: string| required
Your Algolia Search API key.
indicesโ
type: Array<string | DocSearchIndex>
The list of indices and their optional searchParameters to be used for keyword search.
The ordering matters in the list, as results are ordered based on indices order.
While
indexNameis in deprecation, it is required to pass eitherindicesorindexName. Not passing either will result in anErrorbeing thrown.
- JavaScript
- React
docsearch({
// ...
indices: ['YOUR_ALGOLIA_INDEX'],
// ...
});
in case you want to use custom searchParameters for the index
docsearch({
// ...
indices: [
{
name: 'YOUR_ALGOLIA_INDEX',
searchParameters: {
facetFilters: ['language:en'],
// ...
},
},
],
// ...
});
<DocSearch
// ...
indices={['YOUR_ALGOLIA_INDEX']}
// ...
/>
in case you want to use custom searchParameters for the index
<DocSearch
// ...
indices={[
{
name: 'YOUR_ALGOLIA_INDEX',
searchParameters: {
facetFilters: ['language:en'],
// ...
},
},
]}
// ...
/>
indexNameโ
type: string| deprecated
indexName is currently being planned for deprecation. The new recommended property to use is indices.
Your Algolia index name.
While
indexNameis in deprecation, it is required to pass eitherindicesorindexName. Not passing either will result in anErrorbeing thrown.
placeholderโ
type: string|default: "Search docs"| optional
The placeholder of the input of the DocSearch pop-up modal. Note: If you add a placeholder it will replace the dynamic placeholder based on askAi, It would be better to edit translations
askAiโ
type: AskAiObject|string| optional
Your Algolia Assistant ID.
- JavaScript
- React
docsearch({
// ...
askAi: 'YOUR_ALGOLIA_ASSISTANT_ID',
// ...
});
or if you want to use different credentials for askAi and add search parameters
docsearch({
// ...
askAi: {
indexName: 'ANOTHER_INDEX_NAME',
apiKey: 'ANOTHER_SEARCH_API_KEY',
appId: 'ANOTHER_APP_ID',
assistantId: 'YOUR_ALGOLIA_ASSISTANT_ID',
searchParameters: {
// Filtering parameters
facetFilters: ['language:en', 'version:latest'],
filters: 'type:content AND language:en',
// Content control parameters
attributesToRetrieve: ['title', 'content', 'url'],
restrictSearchableAttributes: ['title', 'content'],
// Deduplication
distinct: true,
},
// Enables/disables showing suggested questions on Ask AI's new conversation screen
// NOTE: Only available with version >= 4.3
suggestedQuestions: true,
},
// ...
});
<DocSearch
// ...
askAi="YOUR_ALGOLIA_ASSISTANT_ID"
/>
in case you want to use different credentials for askAi
<DocSearch
// ...
askAi={{
indexName: 'ANOTHER_INDEX_NAME',
apiKey: 'ANOTHER_SEARCH_API_KEY',
appId: 'ANOTHER_APP_ID',
assistantId: 'YOUR_ALGOLIA_ASSISTANT_ID',
searchParameters: {
// Filtering parameters
facetFilters: ['language:en', 'version:latest'],
filters: 'type:content AND language:en',
// Content control parameters
attributesToRetrieve: ['title', 'content', 'url'],
restrictSearchableAttributes: ['title', 'content'],
// Deduplication
distinct: true,
},
// Enables/disables showing suggested questions on Ask AI's new conversation screen
// NOTE: Only available with version >= 4.3
suggestedQuestions: true,
}}
/>
- Filtering:
facetFilters: ['type:content']- Filter by language, version, or content type - Complex filtering:
filters: 'type:content AND language:en'- Apply complex filtering rules - Content control:
attributesToRetrieve: ['title', 'content', 'url']- Control which attributes are retrieved - Search scope:
restrictSearchableAttributes: ['title', 'content']- Limit search to specific fields - Deduplication:
distinct: true- Remove duplicate results
These parameters provide the essential functionality for Ask AI while keeping the API simple and focused.
agentStudioโ
type: boolean| optional | experimental
agentStudio is currently an experimental property. It is targeted to be stable in release 5.0.0.
If agentStudio is true, the Ask AI chat will use Algolia's Agent Studio as the chat backend instead of the Ask AI backend. Learn more on Algolia Agent Studio Docs.
searchParametersโ
type: SearchParameters| optional | deprecated
searchParameters is currently being planned for deprecation. The new recommended property to use is indices.
The Algolia Search Parameters.
transformItemsโ
type: function|default: items => items| optional
Receives the items from the search response, and is called before displaying them. Should return a new array with the same shape as the original array. Useful for mapping over the items to transform, and remove or reorder them.
- JavaScript
- React
docsearch({
// ...
transformItems(items) {
return items.map((item) => ({
...item,
content: item.content.toUpperCase(),
}));
},
});
<DocSearch
// ...
transformItems={(items) => {
return items.map((item) => ({
...item,
content: item.content.toUpperCase(),
}));
}}
/>
hitComponentโ
type: ({ hit, children }, { html }) => JSX.Element | string | Function|default: Hit| optional
The component to display each item. Supports template patterns:
- HTML strings with html helper (recommended for JS CDN):
({ hit, children }, { html }) => html... - JSX templates (for React/Preact):
({ hit, children }) => <div>...</div> - Function-based templates:
(props) => string | JSX.Element | Function
You get access to the hit object which contains all the data for the search result, and children which is the default rendered content.
See the default implementation.
- JavaScript
- React
docsearch({
// ...
hitComponent({ hit, children }, { html }) {
// Using HTML strings with html helper
return html`
<a href="${hit.url}" class="custom-hit-class">
<div class="hit-icon">๐</div>
<div class="hit-content">${children}</div>
</a>
`;
},
});
<DocSearch
// ...
hitComponent={({ hit, children }) => {
// Using JSX templates
return (
<a href={hit.url} className="custom-hit-class">
<div className="hit-icon">๐</div>
<div className="hit-content">{children}</div>
</a>
);
}}
/>
transformSearchClientโ
type: function|default: DocSearchTransformClient => DocSearchTransformClient| optional
Useful for transforming the Algolia Search Client, for example to debounce search queries
disableUserPersonalizationโ
type: boolean|default: false| optional
Disable saving recent searches and favorites to the local storage.
initialQueryโ
type: string| optional
The search input initial query.
navigatorโ
type: Navigator| optional
An implementation of Algolia Autocomplete