A powerful, customizable search widget for websites that combines Algolia's instant search capabilities with AI-powered chat functionality. This monorepo provides both vanilla JavaScript and React implementations.
- Instant Search: Powered by Algolia's lightning-fast search API
- AI Chat Integration: Ask AI feature for complex queries and conversational search
- Keyboard Navigation: Full keyboard support with customizable shortcuts (default: Cmd+K)
- Modal Interface: Clean, accessible search modal with modern UI
- Multiple Experiences: Flexible architecture supporting different search experiences
- TypeScript Support: Full type safety and excellent developer experience
- Customizable: Extensive configuration options for styling and behavior
- Purpose: Drop-in vanilla JavaScript search widget
- Technology: Uses Preact under the hood for performance
- Bundle Size: Optimized for minimal footprint
- Usage: Simple API with global
SiteSearchconstructor
- Purpose: React components and hooks for search functionality
- Technology: Built with React and React InstantSearch
- Features: Full component library including SearchModal, SearchButton, ChatWidget
- Usage: Use individual components or the complete SearchExperience
quick-search/
├── packages/
│ ├── search-js/ # Vanilla JS implementation
│ │ └── src/index.ts # Main SiteSearch class
│ └── search-react/ # React implementation
│ └── src/experiences/ # Search experiences
└── apps/demo/ # Demo application
npm install @algolia/sitesearch-react react react-domnpm install @algolia/sitesearchimport { SearchExperience } from '@algolia/sitesearch-react';
function App() {
return (
<SearchExperience
applicationId="YOUR_APP_ID"
apiKey="YOUR_API_KEY"
indexName="YOUR_INDEX_NAME"
assistantId="YOUR_ASSISTANT_ID"
placeholder="Search your site..."
/>
);
}<!DOCTYPE html>
<html>
<head>
<title>My Site</title>
</head>
<body>
<div id="search-container"></div>
<script src="https://cdn.jsdelivr.net/npm/@algolia/sitesearch/dist/sitesearch.min.js"></script>
<script>
SiteSearch.init({
container: '#search-container',
applicationId: 'YOUR_APP_ID',
apiKey: 'YOUR_API_KEY',
indexName: 'YOUR_INDEX_NAME',
assistantId: 'YOUR_ASSISTANT_ID'
});
</script>
</body>
</html>applicationId: Your Algolia Application IDapiKey: Your Algolia API Key (search-only key recommended)indexName: The Algolia index to searchassistantId: AI Assistant ID for chat functionality
placeholder: Search input placeholder text (default: "What are you looking for?")hitsPerPage: Number of results per page (default: 8)keyboardShortcut: Keyboard shortcut to open search (default: "cmd+k")buttonText: Custom search button textbuttonProps: Additional props for the search buttonagentStudio: Use Agent Studio endpoints for Ask AI chat (optional, defaults to false)
Main component that orchestrates the entire search experience including the button, modal, and all interactions.
The modal container that houses the search interface with backdrop and accessibility features.
Enhanced search input with AI chat toggle, keyboard navigation, and query management.
Displays search results with highlighting, selection states, and keyboard navigation.
AI-powered chat interface for conversational search when direct results aren't sufficient.
Trigger button that opens the search modal with customizable styling and behavior.
- Cmd+K (or custom shortcut): Open search modal
- Arrow Up/Down: Navigate through search results
- Enter: Select highlighted result or trigger AI chat
- Escape: Close modal or clear search
The component comes with a complete CSS implementation that's:
- Responsive: Works on all screen sizes
- Accessible: WCAG compliant with proper focus management
- Customizable: CSS custom properties for easy theming
- Dark Mode Ready: Supports dark/light theme switching
pnpm dev # Start all packages in development mode
pnpm dev:demo # Start demo applicationpnpm build # Build all packages
pnpm build:demo # Build demo application- Monorepo: Bun for efficient builds and caching
- Bundler: Rolldown for fast, optimized bundles
- Language: TypeScript for type safety
- React: React 18+ with hooks and modern patterns
- CSS: PostCSS with autoprefixer and CSS modules
- Testing: ESLint for code quality
/packages/search-js: Vanilla JavaScript implementation/packages/search-react: React components and experiences/apps/demo: Demo application showcasing usage
- Components go in
/packages/search-react/src/experiences/sitesearch/ - Export new components in
/packages/search-react/src/index.ts - Add types to appropriate
.d.tsfiles - Update build configs if needed
pnpm test # Run tests across all packages
pnpm lint # Lint code for style and errorsSiteSearch.init(options): Initialize search widgetSiteSearch.destroy(container): Remove search widget instanceSiteSearch.destroyAll(): Remove all search widget instances
applicationId: string- Required Algolia app IDapiKey: string- Required Algolia API keyindexName: string- Required index nameassistantId: string- Required for AI chatbaseAskaiUrl?: string- Optional AI API endpointagentStudio?: boolean- When true, use Agent Studio endpoints for Ask AI (default: false)placeholder?: string- Search input placeholderhitsPerPage?: number- Results per pagekeyboardShortcut?: string- Keyboard shortcutbuttonText?: string- Button labelbuttonProps?: object- Additional button props
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Update documentation
- Submit a pull request
MIT License - see LICENSE file for details.
For issues and questions:
- Check the GitHub issues
- Review the Algolia documentation
- Visit the demo application for examples
Built with ❤️ using Algolia's powerful search platform and modern web technologies.