Generate DDL to create the full-text search index.
Run it with exec(), which runs a script of several statements. On
PostgreSQL the script holds DO blocks with semicolons inside them, so a
caller that splits it on ; itself would cut them.
Name for the FTS index/virtual table.
Columns to index.
OptionalcontentSource table (for external-content FTS5).
Optionaltokenizer?: stringTokenizer config (e.g. 'porter ascii').
A rank value, in each engine's own direction.
SQLite FTS5: memory_traces_fts.rank (lower is better)
SQLite FTS4: length(offsets(memory_traces_fts)) (higher is better)
Postgres: ts_rank(_tsv, websearch_to_tsquery('english', $1)) (higher is better)
Use relevanceOrder to order the same way on every engine.
Optional_queryPlaceholder: stringAn ORDER BY fragment that puts the best match first on every engine.
SQLite FTS5: memory_traces_fts.rank
SQLite FTS4: length(offsets(memory_traces_fts)) DESC
Postgres: ts_rank(_tsv, websearch_to_tsquery('english', $1)) DESC
Optional_queryPlaceholder: stringGenerate an INSERT to sync external-content FTS after a row insert.
SQLite: INSERT INTO fts_table (rowid, col1, col2) VALUES (expr, ?, ?)
Postgres: UPDATE content_table SET _tsv = to_tsvector(...) WHERE ...
Generate a SELECT joining the FTS index to the content table. This handles the structural difference between FTS5 (separate virtual table joined via rowid) and Postgres (tsvector column on the content table itself).
The base table (e.g. 'memory_traces').
Alias for the content table (e.g. 't').
Alias for the FTS table/column (e.g. 'fts').
FTS index/virtual table name.
FROM/JOIN clause fragment.
SQLite FTS4 full-text search, for sql.js and the IndexedDB adapter: the stock sql.js build compiles SQLite with FTS3 and FTS4 and without FTS5.
Uses FTS4 virtual tables with external content, the porter, unicode61 or simple tokenizer, and rowid joins to the content table. FTS4 has no rank column; relevanceOrder orders by the length of
offsets(), which grows with the number of matching terms, so the best match comes first.