A Trie for Prefix Completions
A trie can store query completions by common prefixes, allowing navigation to one prefix and enumeration of its matching descendants.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace a partial query
With data, database, and date stored, prefix dat can reach all three. Prefix data reaches data and database. See following trie paths.
Choose a completion order
Alphabetical order and popularity answer different questions. Keep the dictionary traversal and ranking separate when both are needed. Order by keys describes the tie rule.[1]
Follow the prefix, then enumerate allowed descendants
Store rail, rails and rain, all sharing prefix rai. Walking that prefix reaches a node with branches L and N. Continuing with l makes rain unreachable and leaves rail and rails as possible completions. See trie prefix traversal.
rai → rail, rails, rain
rail → rail, rails
Exact terminal marker keeps rail available although it has a child
Filter and order suggestions using the public contract
A trie finds prefixes but supplies no built-in relevance policy. Exclude suggestions the current reader may not see. Test a complete term, an empty prefix and a prefix with no descendants.