API Reference
DocSearch v4 is currently in beta. While it's suitable for production scenarios, expect potential improvements and minor issues. Use at your discretion.
- 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.
indexName
β
type: string
| required
Your Algolia index name.
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
docsearch({
// ...
askAi: {
indexName: 'ANOTHER_INDEX_NAME',
apiKey: 'ANOTHER_SEARCH_API_KEY',
appId: 'ANOTHER_APP_ID',
assistantId: 'YOUR_ALGOLIA_ASSISTANT_ID',
},
// ...
});
<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
β
type: SearchParameters
| optional
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 }) => JSX.Element
|default: Hit
| optional
The component to display each item.
See the default implementation.
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βs Navigator API to redirect the user when opening a link.
Learn more on the Navigator API documentation.
translations
β
type: Partial<DocSearchTranslations>
|default: docSearchTranslations
| optional
Allow translations of any raw text and aria-labels present in the DocSearch button or modal components.
docSearchTranslations
const translations: DocSearchTranslations = {
button: {
buttonText: 'Search',
buttonAriaLabel: 'Search',
},
modal: {
searchBox: {
clearButtonTitle: 'Clear',
clearButtonAriaLabel: 'Clear the query',
closeButtonText: 'Close',
closeButtonAriaLabel: 'Close',
placeholderText: undefined, // fallback: 'Search docs' or 'Search docs or ask AI a question'
placeholderTextAskAi: undefined, // fallback: 'Ask another question...'
placeholderTextAskAiStreaming: 'Answering...',
// can only be one of the following
// https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/enterkeyhint#value
enterKeyHint: 'search',
enterKeyHintAskAi: 'enter',
searchInputLabel: 'Search',
backToKeywordSearchButtonText: 'Back to keyword search',
backToKeywordSearchButtonAriaLabel: 'Back to keyword search',
},
startScreen: {
recentSearchesTitle: 'Recent',
noRecentSearchesText: 'No recent searches',
saveRecentSearchButtonTitle: 'Save this search',
removeRecentSearchButtonTitle: 'Remove this search from history',
favoriteSearchesTitle: 'Favorite',
removeFavoriteSearchButtonTitle: 'Remove this search from favorites',
recentConversationsTitle: 'Recent conversations',
removeRecentConversationButtonTitle:
'Remove this conversation from history',
},
errorScreen: {
titleText: 'Unable to fetch results',
helpText: 'You might want to check your network connection.',
},
noResultsScreen: {
noResultsText: 'No results found for',
suggestedQueryText: 'Try searching for',
reportMissingResultsText: 'Believe this query should return results?',
reportMissingResultsLinkText: 'Let us know.',
},
resultsScreen: {
askAiPlaceholder: 'Ask AI: ',
},
askAiScreen: {
disclaimerText:
'Answers are generated with AI which can make mistakes. Verify responses.',
relatedSourcesText: 'Related sources',
thinkingText: 'Thinking...',
copyButtonText: 'Copy',
copyButtonCopiedText: 'Copied!',
copyButtonTitle: 'Copy',
likeButtonTitle: 'Like',
dislikeButtonTitle: 'Dislike',
thanksForFeedbackText: 'Thanks for your feedback!',
preToolCallText: 'Searching...',
duringToolCallText: 'Searching for ',
afterToolCallText: 'Searched for',
// If provided, these override the default rendering of aggregated tool calls:
aggregatedToolCallNode: undefined, // (queries: string[], onSearchQueryClick: (query: string) => void) => React.ReactNode
aggregatedToolCallText: undefined, // (queries: string[]) => { before?: string; separator?: string; lastSeparator?: string; after?: string }
},
footer: {
selectText: 'Select',
submitQuestionText: 'Submit question',
selectKeyAriaLabel: 'Enter key',
navigateText: 'Navigate',
navigateUpKeyAriaLabel: 'Arrow up',
navigateDownKeyAriaLabel: 'Arrow down',
closeText: 'Close',
backToSearchText: 'Back to search',
closeKeyAriaLabel: 'Escape key',
poweredByText: 'Powered by',
},
},
};
getMissingResultsUrl
β
type: ({ query: string }) => string
| optional
Function to return the URL of your documentation repository.
- JavaScript
- React
docsearch({
// ...
getMissingResultsUrl({ query }) {
return `https://github.com/algolia/docsearch/issues/new?title=${query}`;
},
});
<DocSearch
// ...
getMissingResultsUrl={({ query }) => {
return `https://github.com/algolia/docsearch/issues/new?title=${query}`;
}}
/>
When provided, an informative message wrapped with your link will be displayed on no results searches. The default text can be changed using the translations property.

resultsFooterComponent
β
type: ({ state }) => JSX.Element
| optional
The component to display below the search results.
You get access to the current state which allows you to retrieve the number of hits returned, the query etc.
You can find a working example without JSX in this sandbox.
- JavaScript
- React
docsearch({
// ...
resultsFooterComponent({ state }) {
return {
// The HTML `tag`
type: 'a',
ref: undefined,
constructor: undefined,
key: state.query,
// Its props
props: {
href: 'https://docsearch.algolia.com/apply',
target: '_blank',
onClick: (event) => {
console.log(event);
},
// Raw text rendered in the HTML element
children: `${state.context.nbHits} hits found!`,
},
__v: null,
};
},
});
<DocSearch
// ...
resultsFooterComponent={({ state }) => {
return <h1>{state.context.nbHits} hits found</h1>;
}}
/>
maxResultsPerGroup
β
type: number
| optional
The maximum number of results to display per search group. Default is 5.
You can find a working example without JSX in this sandbox
- JavaScript
docsearch({
// ...
maxResultsPerGroup: 7,
});