You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tg sql: the message text and highlighted snippets for search matches #81
Since #79 (#1), message_search is a contentless FTS5 table (content='', contentless_delete=1) on SQLite 3.43 and newer. It keeps only the word index (which words occur in which message), not a second copy of each message's text, sender, chat and files. That made a cache 11–18% smaller.
tg messages search is unchanged: it matches in message_search and reads the text from messages_cache by rowid. Direct SQL loses two things:
SELECT text, sender, chat, files FROM message_search returns NULL for those columns. Joining messages_cache by rowid gives the same data.
snippet() and highlight() don't work on a contentless table, so a tg sql query can't show the matched words in context. No tg command uses them today.
Options considered:
An external-content FTS5 table whose content is a view over messages_cache. snippet() and highlight() would work in SQL, but the sender and chat columns are built from users_cache and chats_cache, which change when someone is renamed, and an external-content index needs the old values to delete a row. The index could drift from the data.
Keep the contentless table and add a view that joins it with messages_cache, so tg sql users get the columns without writing the join.
Add highlighting to tg messages search itself, computed in tg rather than in SQL.
Decision: 2 and 3. A view message_search_text exposes the message's columns plus a column named after the view, so SELECT … FROM message_search_text WHERE message_search_text MATCH 'word' ORDER BY rank works (SQLite flattens the view and passes the MATCH to FTS5; checked on SQLite 3.54.0). tg messages search --snippet returns each match with a short fragment around the matched words, highlighted. snippet() and highlight() in SQL stay unavailable.
Done when tg sql users can query message_search_text with MATCH and get the message text without writing the join, tg messages search --snippet returns highlighted fragments (Latin and Cyrillic, prefixes), the cache stays as small as it is now, and docs/ describe both. Related: #80.
changed the title [-]tg sql: message_search columns are NULL and snippet()/highlight() don't work since the contentless index[/-][+]tg sql: the message text and highlighted snippets for search matches[/+]on Oct 28, 2026
Activity
[-]tg sql: message_search columns are NULL and snippet()/highlight() don't work since the contentless index[/-][+]tg sql: the message text and highlighted snippets for search matches[/+]feat(search): highlighted snippets and the message_search_text view
fix(search): C++ as a plain word, snippets folded and cut like the index
feat(search): highlighted snippets and the message_search_text view
fix(search): C++ as a plain word, snippets folded and cut like the index