Search
A site has a search that needs no server. The build makes an index of the words of each page, and a script of the search page finds the pages of a query in the index. The key search 0 of the site file turns the search off.
The parts
| Part | What it is |
|---|---|
search.json |
The index. |
search/ |
The search page: a form, a line with the count of results (role="status"), and the list of results. |
assets/search.js |
The script of the search page, a JavaScript module. |
{{search}} |
The slot of the form in the header of each page. The form sends the query to the search page as ?q=. |
With panel 1, these parts take the place of assets/search.js:
| Part | What it is |
|---|---|
assets/panel.js |
The loader, a small JavaScript module on each page. |
assets/panel.tcl |
The panel, the groups, the ranking, and the keys, in Tcl. It fills the search page too. |
assets/panel.css |
The look of the panel, with the colors of the style. |
assets/ztcl.mjs, assets/ztcl-host.wasm |
ztcl in the browser. web/ztcl/PIN of Flight Manual has their version and their SHA-256. |
With no JavaScript, the search page says that the search needs JavaScript. Each other page works with no script. The search page loads the index with fetch, so it works on a server and not from a file on the disk.
The index
A word is a run of letters, digits, and _, in lower case, of 2 to 32 characters. ztcl::markdown is two words: ztcl and markdown.
An entry is a thing that a result can name. Its kind is one of these, in this order by default:
| Kind | Entries |
|---|---|
command |
A page with the key usage, a page of a command of the reference, and a command of the reference with no page of the site. The line is its synopsis or its usage. |
option |
An option of a command of the reference. The anchor is the name of the option, as the reference pages of ztcl and ztk have it. |
subcommand |
A subcommand of a command of the reference, such as dict get, on the page reference/dict/get/. |
guide |
Each other page. The line is its description. |
heading |
Each heading of level 2 and 3, with its anchor. The line is the title of its page. |
text |
A page that has the words of the query in its text. These are the words of the index, and they have no entries. |
The key kinds of the site file changes the order and adds kinds, and the page key entry gives the kind of a page. The key reference names a folder of a command reference in the format of ztcl (docs/reference/*.tcl of ztcl and ztk). The build reads the files as data and runs none of their code: it takes command, synopsis, summary, option, and subcommand, and skips each other declaration.
The index has:
- the names of the groups of the results, in their order;
- each page: its path, its title, its meta description, the number of its group, and the usage line of a command;
- each heading of level 2 and 3: its page, its anchor, and its text;
- the kinds of the entries, in their order, and each entry: its kind, its page, its anchor, its title, and one line of text (format 2).
- each word and the pages that have it. A list of pages is the steps between the page numbers in base 36, so a word of each page costs about two bytes for each page.
On a site of 20 pages or more, a word of more than half of the pages is a common word, such as "the". The index lists the common words with no pages, and a query skips them. A query of common words only gives the pages with each word in the title or in a heading.
The index of the 337 Markdown files of docs/ of ztcl (2.4 MB of text) is 516 KB. The server sends it compressed.
A query
A page is a result when it has each word of the query. The last word also matches each word that starts with it, so the results show while the reader types. A query that ends with a space has only whole words.
The order of the results is the score of each page: 4 for each word of the query in the title, and 2 for each word in the heading with the most words of the query. Pages with the same score are in the order of the menu. The link of a result goes to that heading, when a heading has a word of the query.
The panel
The panel finds the pages of a query by the same rules. Its score also gives 1000 to a command whose name is the query, and 100 to another page whose title is the query. It shows the 10 best results in their groups. The group of an exact name goes first, so an exact command name is always the first result. A result shows its title and one line: the usage of a command, the best heading, or the description, with the first word of the query marked.
The field and the panel follow the combobox pattern of ARIA: role="combobox", aria-expanded, and aria-activedescendant on the field, a listbox with a role="group" for each group, and a status line with the count of results. Each result is a link, so a click or a tap opens it.
Measured on 2026-12-02 with a headless Chromium on Linux x86_64, the cache empty, on the ztcl docs site (968 pages):
| Bytes | |
|---|---|
ztcl-host.wasm |
2,594,043 (888,276 with gzip) |
ztcl.mjs |
55,619 (16,205 with gzip) |
panel.tcl |
about 19,000 (5,651 with gzip) |
search.json |
587,379 (150,561 with gzip) |
| First key to the panel | A key with the panel loaded | |
|---|---|---|
| Desktop | 343 ms | 20 ms |
| Desktop, CPU 4 times slower | 733 ms | |
| Phone size | 268 ms |
tests/search.test.mjs checks the results of fixed queries on the index of examples/basic.
Next: Plugins.