Expand description
Exact best-first top-k search over a Trie with weighted edit costs.
Each queued trie node carries one banded row of the edit-distance matrix.
A row cell k at trie depth j stands for query prefix length
i = j + k - W, where W = budget / c_indel_min is the band half-width.
A node is queued with a lower bound on the cost of every term below it, so
the first terminal popped is always the best remaining one.
The budget, the band and the candidates always use the weighted costs of
CostModel. The order of the results is set by Ranking: by default
(Ranking::Coarse) terms are ranked by the weighted cost rounded up to
whole units of 16 (whole_units), then by higher weight, then by lower
term id, so the weight decides between terms whose costs round to the same
number of units. This is not a count of edits: the x1.5 factor on the
first byte makes an ordinary (non-neighbouring-key) edit there cost 24,
i.e. two units, while a neighbouring-key substitution there costs 12 (one
unit) and a transposition 18 (two units); two cheap edits (8 + 8) count as
one.
Ranking::Exact ranks by the exact weighted cost instead, then weight,
then id. In both modes Hit::cost is the exact weighted cost.
Searcher::search_prefix is the autocomplete variant: a term costs what its best prefix
costs. See docs/design/prefix-mode.md.
Queries and terms are compared per Unicode scalar value (a symbol), not per
UTF-8 byte; for ASCII the two are the same. See docs/design/unicode.md.
Structs§
- Hit
- One result.
- Output
- Hits in ranking order plus work counters.
- Search
Config - Search parameters.
- Searcher
- A reusable search context. It keeps its priority queue and scratch buffers
across queries; the returned
Outputis still allocated per query. - Stats
- Work counters for one search.
Enums§
- Ranking
- How results are ordered.
- Search
Error - Why a search was rejected.
Constants§
- MAX_
QUERY_ LEN - Longest accepted query, in symbols (code points; bytes for ASCII).