FlexSearch

Boltdocs ships with **FlexSearch** as its default offline search engine. During the build phase, Boltdocs scans all markdown files and prepares a bounded runtime search asset. The client loads the asset and FlexSearch lazily when the search dialog opens, then performs high-speed local matching with no network queries.

The useSearch() HookLink

To build a custom search bar, query inputs, or inline list search, use the useSearch() hook from boltdocs. It exposes live query state, search results, and dialog control callbacks.

tsx
import { useRoutes, useSearch } from 'boltdocs'

export function MySearchBar() {
  const { routes } = useRoutes()
  const {
    query,
    setQuery,
    list,
    isOpen,
    setIsOpen,
    handleSelect,
    status,
  } = useSearch(routes)

  return (
    <div className="search-container">
      <input
        value={query}
        onChange={(event) => setQuery(event.target.value)}
        placeholder="Type to search..."
        onFocus={() => setIsOpen(true)}
      />
      {isOpen && status === 'ready' && list.length > 0 && (
        <div className="search-dropdown">
          {list.map((result) => (
            <button
              key={result.id}
              type="button"
              className="search-item"
              onClick={() => handleSelect(result.path)}
            >
              <span className="search-title">{result.title}</span>
              <p className="search-desc">{result.snippet ?? result.bio}</p>
            </button>
          ))}
        </div>
      )}
    </div>
  )
}

SearchResultLink

PropertyTypeDescription
idstringStable result identifier.
pathstringThe resolved absolute path (e.g. '/docs/guides/getting-started').
titlestringThe matching page or heading title.
biostringThe page or heading breadcrumb.
snippetstring | undefinedA focused content excerpt around the match, when available.
isHeadingbooleanWhether the result points to a heading anchor.

Local Development vs. ProductionLink

  • Local Development: The search index updates incrementally via Vite HMR as you edit files, making live search change testing seamless.
  • Production: The bounded search asset and FlexSearch engine load asynchronously only when the user interacts with the search input, keeping the initial bundle small. Results are filtered by the active locale and version before the result limit is applied.
Last updated on October 18, 2026

Was this page helpful?