Search / As you type

As you type

A search box that answers while its reader types sends a word typed halfway: crypt on its way to cryptography. With prefix, Search reads the last word of the text as the start of a word too, so the box finds every document with a word that starts with it, as the reader types each letter.

const courses = store.index<{ name: string }>('courses', { fields: { name: 1 } })
await courses.setMany([
	{ id: 1, value: { name: 'Cryptographic methods of information security' } },
	{ id: 2, value: { name: 'Cryptanalysis' } },
	{ id: 3, value: { name: 'Cryptography' } },
	{ id: 4, value: { name: 'Foundations of cryptography' } },
])
const { hits } = await courses.search({ text: 'crypt', prefix: true })
hits.map(hit => hit.id) // ['2', '3', '4', '1']
courses = store.index("courses", Course, fields={"name": 1})
await courses.set_many([("1", Course("Cryptographic methods of information security")), ("2", Course("Cryptanalysis"))])
result = await courses.search("crypt", prefix=True)
courses, err := search.OpenIndex[Course](store, "courses", search.Fields{"name": 1})
result, err := courses.Search(ctx, "crypt", search.Prefix())
let courses = store.index::<Course>("courses").field("name", 1.0).open()?;
let found = courses.search("crypt").prefix().run()?;

Without prefix, crypt is a word of its own: it finds a course named Crypt, and none of the four above.

Which word is a prefix

Only the last word, and only while the reader may still be typing it:

TextRead as
cryptcrypt, and every word that starts with it
methods cryptmethods whole, then crypt and the words it begins
crypt (a space)crypt whole: the reader finished the word
crypt,crypt whole: a mark ends a word as a space does
cc whole: one letter would begin half the words of a page

A word is read as Search reads every word: in lower case, accents off, ё as е. Crypt and crypt are the same prefix, in any script.

How a prefix ranks

The words a prefix begins count as one word in each field: a document holding two of them counts both, as it would one word written twice. They weigh half their field's weight, less than the stem of a Cyrillic word, which weighs three quarters, so a document holding the word typed comes before one holding only a longer word, unless that word is far rarer or its field far shorter.

Among the words a prefix begins, the shortest field ranks first, as BM25 ranks any word: cryptograph finds Cryptography, then Foundations of cryptography, then Cryptographic methods of information security.

Typos and a prefix

A word typed halfway is no typo while it begins a word the index holds: cardi is one letter from cards, and still finds cardigan rather than being read as cards. A last word that begins nothing the index holds is corrected as any word is, and corrected says so: cryptograhpy reads as cryptography.

A typo inside a prefix is not forgiven as a prefix: a last word that begins nothing is read only as the whole word nearest it, under the rules of typos, and its prefix is then that word.

Limits and defaults

WhatValue
prefixoff unless the search says
the shortest prefixtwo letters
words a prefix is read asthe 64 most held in each field
what a word it begins weighshalf its field's weight
words before the lastwhole, always

A prefix reads the postings of every word it begins before the search scores, so a short prefix on an index of many documents reads more than a whole word would. The 64 most held words bound it.

Edit this page on GitHub Updated 31 October 2026

esc
↑↓ navigate ↵ open ⇥ filter 0 results