All docs pages
Docs

Text search

Fast keyword search over the app's own records, ranked by how well they match.

In stackly.json and the CLI it is search. It has no price of its own; see What features cost.

search · optional · needs database · SQLite full-text search (FTS5) in D1

Fast keyword search over the app's own records, ranked by how well they match, with a highlighted snippet.

Turn it on

"features": ["backend", "database", "search"],
"bindings": ["APP_DATABASE"]

Use it

import { searchIndex } from "#/lib/search.server";

const posts = searchIndex("posts", ["title", "body"]);

await posts.add(post.id, { title: post.title, body: post.body }); // after saving; add again to update
await posts.remove(post.id);                                       // after deleting
const hits = await posts.search("garden tools", { limit: 20 });     // [{ id, score, snippet }]
  • Keep the index in step with the table in the same server function that writes the record.
  • snippet is a list of { text, match } parts: render matching parts with <mark>, never as HTML.
  • Words match by stem ("gardening" finds "garden"), the last word also as a prefix while someone types, and accents are ignored.
  • An index's fields are fixed when first used; to change them, clear() it and add the records again.

Limits

Index names and fields: lowercase letters, digits or _, up to 40 characters. 1 to 8 fields. 12 words per query.

Don't

Semantic or AI search is not offered; this is keyword search.

Locally

stackly dev builds the index in the local database.

All app features