Search

Instant static search with Pagefind. No service to run or pay for.

Search is powered by Pagefind, which indexes the built HTML at deploy time and downloads only the fragments a query needs. That keeps search fast on large sites without shipping a giant index to every visitor, and there is no hosted service to run or pay for.

Search works in production builds and astro preview, not in astro dev (the index is generated after the build).

Using a different search engine

Compose ships one engine, Pagefind, and does not wrap it in an adapter API you have to learn. If you would rather use something else, whether a hosted backend or an in-memory engine with typo tolerance, you have the source, and search lives in one file per app:

AppFile
Astrosrc/lib/pagefind.ts
Nextlib/pagefind.ts

That file exports exactly two things the rest of the theme uses:

  • loadPagefind() returns an object with search(term), resolving to { results } where each result has an async data().
  • renderResult(d) turns one result into the theme’s .search_result markup. It reads d.url, d.meta.title, and d.excerpt, where excerpt is a pre-highlighted HTML snippet.

Match that shape with your own engine and nothing else in the theme has to change. The nav dropdown, the /search page, the empty state, and the styling all keep working. The two call sites are components/Search and the /search page.

search.engine in the config accepts other values for forward compatibility, but only "pagefind" is wired up. Anything else warns at build time and falls back. Swapping engines means editing the file above, not flipping a config value.