Search
The docs plugin ships a full-text search bar backed by docfind — Microsoft's Rust-based document search engine (FST + FSST + RAKE keyword extraction). The search index is embedded into a WASM module at build time, so searching happens entirely in the browser with zero network round-trips.
How it works
- At build time, the docs plugin collects every documentation page (title, category, href, body, and optional frontmatter
keywords). - The vendored docfind builder — a WASM module embedded into the krate binary — runs in-process (via a pure-Go WebAssembly runtime) to build the index and embed it into a search WASM module.
- The plugin writes the searchable module + a small JS glue to
docs/search/in the output directory:
dist/docs/ search/ docfind.js # ~3 KB hand-written browser glue docfind_bg.wasm # search module with the docs index embedded search.js # the search UI (trigger, modal, keyboard nav) search.css # search UI styles data/ search-index.json # classic JSON fallback (always written) - In the browser, pressing the search button (or Ctrl/Cmd+K) opens a command-palette-style dialog. Typing queries the WASM index locally: fuzzy matching with Levenshtein distance, ranked by relevance. The UI falls back to the JSON index automatically if the WASM module fails to load.
Configuration
docs({ contentDir: "content/docs", title: "Docs", search: { enabled: true, // default: true engine: "docfind", // "docfind" (default) | "json" maxResults: 8, // default: 8 }, }) | Option | Default | Description |
|---|---|---|
enabled | true | Turn the search bar on/off |
engine | "docfind" | "docfind" builds the embedded WASM index; "json" uses search-index.json only |
maxResults | 8 | Max results shown |
Improving results
docfind extracts keywords from titles, categories, and bodies using the RAKE algorithm. Add explicit keywords in frontmatter for pages whose content doesn't capture the right terms:
--- title: Signals keywords: [reactive, createSignal, createEffect, createMemo, state] --- Keywords are weighted highest, then title words, then body phrases.
No subprocess, no temp files
The index build runs inside the krate process. The Rust builder module is compiled once and go:embed-ed into the krate binary; documents are passed through WASM memory directly. There's no docfind CLI dependency at build time and no documents.json written to disk.
Customizing the UI
The search UI lives in dist/docs/search/search.js and search.css after a build. The trigger/dialog markup is generated by the docs plugin (.krate/gen/docs/SearchBar.tsx); you can restyle it by overriding the .krate-search-* classes in your own stylesheet.