fts5IndexFor method
Return (and lazily build) the corpus-aware FTS5 index for
tableName.columnName. The index is rebuilt automatically
after any mutation of tableName.
Implementation
Fts5Index fts5IndexFor(String tableName, String columnName) {
final key = '${tableName.toLowerCase()}:${columnName.toLowerCase()}';
final cached = _fts5IndexCache[key];
if (cached != null) return cached;
final t = _tables[tableName];
if (t == null) {
throw StateError('No such table: $tableName');
}
final colIdx = t.columns.indexWhere(
(c) => c.name.toLowerCase() == columnName.toLowerCase(),
);
if (colIdx < 0) {
throw StateError('No such column: $tableName.$columnName');
}
final docs = <String>[
for (final row in t.rows) (row[colIdx] ?? '').toString(),
];
final idx = Fts5Index.build(docs);
_fts5IndexCache[key] = idx;
return idx;
}