Overview
The@docsearch/js package provides a simple JavaScript API that works in any browser environment. You can use it with or without a build tool.
Installation
- Package Manager
- CDN
Install DocSearch using your preferred package manager:Then import in your JavaScript:
Quick Start
Add a container element
Add a container element where DocSearch will render the search button:
Use a container element (like
<div>), not an <input>. DocSearch generates a fully accessible search button for you.Complete HTML Example
Here’s a complete working example using the CDN:index.html
Configuration Options
Basic Configuration
The minimum required configuration:Placeholder Text
Customize the search input placeholder:Search Parameters
Add Algolia search parameters:Transform Search Client
Modify the search client before queries:Transform Items
Post-process search results:Programmatic Control
Thedocsearch() function returns an instance with methods for programmatic control:
Lifecycle Callbacks
Listen to lifecycle events:Ask AI Integration
Basic Ask AI
Enable AI-powered conversational search:Ask AI with Configuration
Customize Ask AI behavior:Open Ask AI Programmatically
Sidepanel Integration
For a better AI experience, use the sidepanel component:Custom Templates
Customize how results are rendered using thehitComponent and resultsFooterComponent options:
Custom Hit Component
Custom Footer Component
Translations
Customize UI text:Module Bundler Example
If you’re using a bundler like Webpack, Vite, or Rollup:main.js
Styling
Customize DocSearch appearance with CSS:custom.css
Complete Production Example
Here’s a complete example with all best practices:index.html
Troubleshooting
Search button not appearing
- Verify the container element exists:
document.querySelector('#docsearch') - Check browser console for errors
- Ensure DocSearch CSS is loaded
- Verify you’re calling
docsearch()after DOM is ready
Modal not opening
- Check if JavaScript errors are preventing execution
- Verify credentials are correct
- Test keyboard shortcut (Ctrl+K) and button click separately
No search results
- Verify your index has data in Algolia dashboard
- Check
searchParameters.facetFiltersaren’t too restrictive - Test with a known indexed term
- Check browser network tab for API errors
Next Steps
API Reference
Explore all configuration options
Styling
Customize the appearance of DocSearch
Ask AI
Add AI-powered conversational search
React Integration
Use DocSearch with React
