Deploying Lyra Search
Embedded full-text search engine for edge, deploy Lyra indexes with your app or as a service.
PlatformsIntermediate
Why
Lyra is a 2KB full-text search engine that runs in-browser, on edge Workers, or Node with no external service. It supports BM25 ranking, typo tolerance, and multi-language stemming out of the box.
Platform-as-a-Service adoption grew 24% in 2024 as teams shift from VM management to git-push deploys. the cloud infrastructure market reached $330B in 2024, growing 22% year-over-year (Synergy Research), and PaaS layers capture the majority of new workloads.
When
Use Lyra for search in static sites, edge apps, and offline-first PWAs. Avoid for datasets >100K docs — use Meilisearch/Typesense.
How
1. Install — npm i @lyrasearch/lyra
2. Create index — const db = lyra({ schema: { title: "string" } })
3. Insert — lyra.insert(db, { title: "Hello" })
4. Search — lyra.search(db, { term: "hello" })
5. Persist — lyra.save(db) to JSON, load with lyra.load
6. Deploy — index ships with your app bundle, no server needed
Example
import { create, insert, search } from "@lyrasearch/lyra";
const db = create({ schema: { title: "string", author: "string" } });
insert(db, { title: "The Great Gatsby", author: "Fitzgerald" });
const result = search(db, { term: "gatsby" });
console.log(result.hits); // [{ title: "The Great Gatsby", ... }]
// Edge deploy — index in Worker
export default { async fetch() {
return Response.json(search(db, { term: "query" }));
}};
Common Problems
- ⚠Index too large for edge — 100K+ docs exceeds Worker memory, pre-filter or shard
- ⚠Search slow on large index — no configuration tuning, reduce schema fields
- ⚠Configuration drift between environments — use infrastructure-as-code (Terraform/Pulumi) to keep dev/staging/prod identical
Best Practices
- ✓Pre-build the index at build time and ship as JSON — load with lyra.load at runtime
- ✓Use Lyra's stemming and stop-words for your language — improves relevance
- ✓Set up health checks and graceful shutdown — handle SIGTERM to drain in-flight requests before exit