Autocomplete terms are often phrases, not single words - "new york", "new jersey". Today you confirm the engine already handles them, because a space is just another character on the path, and a mid-phrase prefix completes correctly.
Complete multi-word terms from a prefix that spans a space, distinguishing it from a prefix that stops before the space.
Nothing in the trie ever assumed a term was a single word. A space is just another
rune, so new york is stored as the path n-e-w-space-y-o-r-k, and every
operation - insert, prefix walk, completion, ranking - treats it like any other
character. Typing new completes to all three terms that start with it, ranked by
weight; the engine does not care that two of them contain a space.
The interesting boundary is the space itself. The prefix new (trailing space)
walks past the space, so it only reaches terms that actually have a space there -
new york and new jersey - and excludes newark, whose fourth character is a,
not a space. This is why phrase autocomplete works for free: the space is a
first-class character in the key, so a person can keep typing straight through it
and the completions narrow exactly as they should.
// No new code: a space is an ordinary rune in the key, so the phrase// "new york" is just the path n-e-w-space-y-o-r-k. The prefix "new "// walks through the space and excludes "newark", whose fourth rune is 'a'.// This lesson pins that phrases and mid-phrase prefixes already work.