astro-d1-search
Site search for Astro, backed by Cloudflare D1 (SQLite FTS5): build-time indexing, an injected search API, bm25 + recency ranking.
Running in production on zander.wtf/search — see theExamples guide for its full source.
What you get
- Build-time indexing of any markdown or MDX — content collections, standalone pages, anything on disk — into a D1 full-text index.
- An injected API endpoint (
GET /api/search) with bm25 + recency ranking, highlighted snippets, type filtering, input validation and edge caching. - A query function (
searchIndex) for server-rendered search pages that hit the D1 binding directly, with no HTTP round trip. - Content-type agnostic: types are strings you choose, so one index can serve site-wide search, per-section search, and even several sites at once.
Requires the @astrojs/cloudflare adapter. The rest of your site stays fully static — only the search endpoint runs server-side.
Guides
Getting started
Install the package, create a D1 database, and get a working search endpoint.
Indexing content
How sources map files to URLs, which frontmatter is read, and what the markdown stripper keeps.
Search pages
Query D1 directly from a server-rendered Astro page, or hit the injected endpoint from the client.
Deploying
CI ordering, API token scopes, local development, and sharing one database across sites.
Examples
A real site running the package end to end, with links to every file involved.
Reference
Configuration
Every option accepted by the integration, with its default and what it affects.
API endpoint
Request parameters, response shape, validation rules, caching and injection safety.
Ranking
How bm25 weights and the recency multiplier combine into a score, and how to tune them.
Exports
The three entry points, every exported function and type, and which one to import where.