Skip to main content
DocSearch is built on Algolia’s powerful search infrastructure, combining a web crawler, search API, and customizable UI components to deliver instant search for documentation sites.

Architecture Overview

DocSearch consists of three main components that work together:
1

Web Crawler

The Algolia Crawler extracts content from your documentation pages using configurable CSS selectors and builds a searchable index.
2

Algolia Search Index

Your documentation content is stored in an Algolia index, optimized for fast, typo-tolerant search with ranking and filtering capabilities.
3

Search UI Components

React or JavaScript components integrate into your site, providing a modal search interface with keyboard shortcuts and AI-powered answers.

Search Flow

When a user searches your documentation, here’s what happens:

1. Query Input

As users type in the search box, DocSearch sends queries to Algolia with debouncing to optimize performance:

2. Search Processing

Algolia processes the query using:
  • Typo tolerance: Handles misspellings automatically
  • Prefix matching: Returns results as you type
  • Ranking algorithm: Orders results by relevance
  • Highlighting: Emphasizes matching terms

3. Results Rendering

Results are grouped by hierarchy level (headings, content) and displayed in the modal:

Component Integration

DocSearch integrates with your site through a React provider pattern:
The provider manages:
  • Modal state: Open/closed status
  • Keyboard shortcuts: Cmd+K, / to open
  • Search queries: Input and results
  • Navigation: Moving between results
  • Ask AI state: Toggle between search and AI modes
The DocSearch component is fully accessible with ARIA attributes and keyboard navigation support.

State Management

DocSearch uses React hooks to manage state:

State Transitions

Programmatic API

You can control DocSearch programmatically using refs:

Available Methods

Search Parameters

Customize search behavior with parameters:
Search parameters are passed directly to the Algolia search client for advanced query customization.
Search across multiple indices for versioned documentation:

Performance Optimizations

DocSearch includes several optimizations:
  • Debounced queries: Reduces API calls while typing
  • Request caching: Stores recent results
  • Lazy loading: Components load on demand
  • Virtual scrolling: Efficient rendering of large result sets
  • Prefetching: Loads resources on hover
The DocSearch component requires a valid Algolia API key and app ID. Keep your search API key public-safe (search-only permissions).

Next Steps

Indexing

Learn how the crawler indexes your documentation

Ask AI

Enable AI-powered answers for your search

Styling

Customize the appearance of DocSearch

API Reference

Explore all configuration options