@mistriwork/search-sqlite
v1.4.2
Published
SQLite FTS5 search provider pack for mistri Apps, over Node's built-in node:sqlite with zero extra dependencies.
Maintainers
Readme
@mistriwork/search-sqlite
SQLite FTS5 as the search provider for a mistri App's search blocks.
What it is
Search is an index, never a source of truth. The index holds a copy of the fields a resource declares searchable, keyed by the record's primary key, and answers a phrase with keys; the rows are re-read from the database under the reader's own grants. The pack holds only what is SQLite's:
SqliteFtsIndex: one FTS5 table per collection in one file, on Node's built-innode:sqlite(zero extra runtime dependencies). It writes a tenant's scope as an exact match on a column, ranks by bm25 with an earlier declared field weighing more (full-text ranking: a rare word in a later field can still outrank a common word in an earlier one), and rebuilds a table when a declaration adds a field — FTS5 tables cannot be altered. Collection and field names must be word characters; anything else is refused rather than quoted.sqliteSearchConnectionOf&sqliteSearch: validates connection entries and creates aSearchProviderwhoseclose()releases open SQLite handles.
How it plugs in
Pass the provider to createHandler({ search }) from @mistriwork/mistri/handler,
or plug it into a Registry with plugSearch from @mistriwork/mistri/search:
import { createHandler } from '@mistriwork/mistri/handler';
import { sqliteSearch } from '@mistriwork/search-sqlite';
const mistri = createHandler({
config: './mistri.json',
basePath: '/desk',
publicOrigin: 'https://example.com',
search: sqliteSearch([{ name: 'fts', file: './search.db' }]),
});An App names the connection in its resource:
resources: { ticket: { search: { connection: 'fts', fields: ['subject', 'requester.name'] } } }The file is opened on first use. :memory: holds the index in the process
only, like the built-in memory provider, and suits tests; a file survives
a restart, so no reindex is needed after one. ${VAR} references in file
expand when the file opens.
What it is not
- Postgres tsvector. Use
@mistriwork/search-postgreswhen your deployment runs PostgreSQL and wants GIN-indexedtsvectortables beside its database. - A large catalog. FTS5 in one file suits moderate tables. A large catalog wants a dedicated engine such as Typesense.
