Developer docs
14. Search
On this page
14.1 Messages (MessagesService/Search)
chat_id = 0 searches every chat I am an active member of; otherwise one chat I can read
(including public channels I haven’t joined). Results never include deleted messages, messages
deleted for me, or messages before my “clear history” point. Filters: from_user_id, topic_id,
filter (media kind, links, voice, music, mentions of me, pinned), min_date/max_date (unix ms,
inclusive). Media captions, document/audio file names (+ audio title/performer), poll questions and
options, and link-preview titles are searchable.
Ordering: sort = SORT_DATE (default, newest first; page with offset_id, and for global search
also offset_date + offset_chat_id of the last result) or SORT_RELEVANCE (page with
offset = previous next_offset; relevance is computed over the newest 500 candidates).
MessagesSlice.highlights[i] belongs to messages[i]: UTF-16 TextRanges in Message.text and in
media.document.file_name, plus exact_phrase and a score only comparable within one response.
Matching (informative; the server is authoritative and may improve it without a protocol change):
- Text is normalized: NFKC (full/half-width), full Unicode case folding (ß→ss, final sigma, Turkish
İ/ı → i), Latin/Greek/Cyrillic/Hebrew/Arabic diacritics removed (é→e, ё→е, Vietnamese tones,
niqqud, harakat; й is kept), Traditional→Simplified Chinese (OpenCC character tables, incl.
Taiwan/Hong Kong variants), katakana→hiragana,
ーignored, Arabic/Persian letter variants folded (أ إ آ → ا, ى → ي, ة → ه, ی → ي, ک → ك), Arabic-Indic digits → 0-9, ZWNJ, variation selectors and emoji skin-tone modifiers ignored. - Chinese/Japanese/Korean are matched as substrings anywhere in the text (1-character queries work); Thai/Lao/Khmer/Myanmar likewise, on grapheme-cluster boundaries.
- Other scripts are matched by word prefix: every query word must start a word of the message.
Extra forms also match: German ue/oe/ae spellings (Müller = Mueller), elided articles
(l’école → école), domain suffixes (www.github.com → github.com), and stems (Snowball / light
stemmers for en es pt fr de it nl tr sv da no fi hu ro ru hi ar; Hebrew one-letter prefixes)
— using
Message.langwhen known. @username,#hashtag, URL hosts and emoji (incl. ZWJ sequences) are tokens of their own.- Ranking: whole query as a phrase > all words; exact spelling (diacritics, script) boosts; stem/alternate-only matches rank lower; newer messages and contacts’ messages rank higher.
Index layout (informative, server-internal): in-chat search reads a GIN over each message’s
token array; global search (chat_id = 0) reads a btree postings table holding the same tokens
one row per (token, message), so its cost grows linearly, not super-linearly, with the number of
chats searched. Both layouts return identical results (same membership, clear-history,
delete-for-me and filter semantics); see SECURITY.md §2.1.
Secret chats are never on the server: clients index them locally (the official app uses SQLite FTS5 with the trigram tokenizer inside an SQLCipher database).
14.2 People and chats (UsersService/Search)
Searches me, my contacts (also by my local alias), the peers of my private chats, my groups and
channels, and public users/chats (those with a username). Name matching uses the normalization
above plus pinyin for Chinese names (full zhangsan, initials zs, mixed zhang三, every reading
of polyphonic characters) and Hangul initial consonants (ㄱㅁㅅ → 김민수). hits is the ranked
list: exact @username first, then contacts, my chats, public; name_ranges are UTF-16 ranges in
first_name + " " + last_name (users) or title (chats). Users without a username are not
discoverable by strangers by name.
13.5 Translation
Message.lang: BCP-47 language detected by the server on send/edit with a local detector (no external call per message). Chinese is reported aszh-Hansorzh-Hant.TranslateMessages(chat_id, message_ids ≤ 20, to_lang, auto)→ per message{text, entities, from_lang, skipped}. Entities are re-based onto the translated text (UTF-16). Custom emoji, mentions, code, pre, URLs, e-mails, bot commands, hashtags, cashtags and phone numbers are never sent to the provider and come back verbatim; text links keep their URL. A message already into_lang(and, withauto, one in mydo_not_translatelist) is returned withskipped. HTML cards are translated throughfallback_textonly. Secret chats can’t be translated by the server (clients translate them on-device).TranslateText(text, entities | parse_mode, to_lang)— “translate before sending”.TranslationSettings{translate_to, do_not_translate[], hide_translate_button}viaUsersService/Get|SetTranslationSettings, synced asUserEvent.translation_settings;Dialog.auto_translateviaUpdateDialog{auto_translate}.- Errors:
503 TRANSLATION_UNAVAILABLE(no provider),420 TRANSLATE_QUOTA_EXCEEDED(daily character quota of the user or the server;retry_after= seconds until the UTC day ends),420 TRANSLATE_PROVIDER_QUOTA,420 FLOOD_WAIT,400 TO_LANG_INVALID,502 TRANSLATE_FAILED. Results are cached by content (an edit invalidates the message’s entries).
13.6 Language of server-made text
Login codes (in-app, SMS, e-mail subject/body), the “new login” notice, push previews (media
labels, group sender prefix, call titles, APNs fallback alert incl. plurals) and suggested folder
titles are rendered in the recipient’s language: the device’s ClientHello.lang (HTTP:
Accept-Language), remembered per session and per user (the latest), then the user’s
TranslationSettings.translate_to, then English. 24 locales are shipped; non-English catalogs are
machine drafts. Forum General (topic id 1) is stored untitled and mini-app data is a structured
ServiceAction.web_app_data_sent, so clients localize both themselves.
Generated from docs/PROTOCOL.md in the Telvoro repository. Wire names such as televo.v1 are unchanged.