Add Search Autocomplete to Your Vibe Project: From 'One Typo, Zero Results' to 'Found Before You Finish Typing'
The search box gets opened many times a day, but few people actually find anything: autocomplete takes the job of guessing the word off the user's hands. Merge popular queries, user history, and the content index; add pinyin initials and one-character typo fixes; mind keyboard and mobile details; debounce, cache, and keep the LLM as a fallback — then iterate on three numbers. The walk-through project, people, and numbers in this guide are fictional.

One typo, and search answers "nothing found"
Anan built a recipe app called "What's for Dinner". Two months after launch, the app itself was in good shape: every recipe had been tested by hand, the steps were clearly written, and the photos were real shots. But the numbers kept bothering him. The search box was opened many times a day, yet few people actually found a recipe and opened it. When he asked a few users, the problem turned out to be right at the door of the search box. Someone wanted "braised pork", typed "braised por", and waited for suggestions to pop up below — nothing did. Someone else typed "tomato egg stir-fry" with a typo, hit search, and got back "no results found". Users did not refuse to search; they were left hanging halfway through typing.
The problem was not the search algorithm itself, but the missing autocomplete step. Anan's search was all or nothing: type the whole word, letter-perfect, and you got a hit; miss one character or stop halfway, and you got zero results. But typing is guesswork by nature. People type while they think, stop halfway when half the word comes to mind, mistype a letter, or pick the wrong pinyin candidate. Autocomplete takes the job of guessing the word off the user's hands: you type two characters, and it hands you the most likely complete words — you just tap one. Without that step, the search box becomes a spelling test, and everyone who fails it walks away.
One thing to make clear first: the author, the app, and the full set of numbers in this guide are fictional examples. The method itself is general — follow it as written. The "What's for Dinner" app below is a fictional recipe app, "Anan" is a fictional author, and the funnel numbers used to walk through the method are made up to explain it. They are not backend data from any real product. As you read, do not worry about where the numbers come from; focus on whether the approach and the order of steps are right.
Where suggestions come from: three sources, merged into one list
Suggestions do not appear out of thin air; they come from three sources. The first is popular queries: what everyone has been searching for lately — seasonal dishes, a recipe that just went viral. Popular queries work for brand-new users because they need no personal data; the downside is they know nothing about you, so everyone gets the same list. The second is the user's own history: what this person searched for and opened before. History is precise — someone who often searches for "low-calorie meals" should see their usual low-calorie dishes first the moment they type one character; the downside is that new users have no history, so this source is empty for them. The third is the content index: things that genuinely exist in your library. A user types "tomato", and the library holds "tomato egg stir-fry", "tomato beef stew", and "tomato fish soup" — those three are the safest suggestions of all, because tapping one is guaranteed to return content instead of leading to a zero-result page.
The three sources must be merged into a single list, not displayed side by side. Merge them by deduplicating first, then ranking, then cutting off the tail. Deduplication means the same phrase coming from two sources appears only once: if "tomato egg stir-fry" is both in the user's history and in the popular list, it shows up once. Ranking decides what the user sees first. A solid default order is: the user's own history first, because that is what they are most likely to tap again; then prefix matches from the content index, because those are guaranteed to return results; popular queries last, to fill out the list. The logic is simple: first offer "what they most likely want", then "what is guaranteed to have results", and finally "what everyone is searching for".
List length matters too: 6 to 8 items is usually enough. Beyond 8, nobody scrolls down, so the extra items are computed for nothing; below 4, the autocomplete looks thin, and users feel the search box has little to offer them. One more rule: every item in the list should be a phrase that returns results when tapped. If your library does not have a "tomato beef stew" recipe at all, do not dangle it in the suggestions as bait — a user who taps it and lands on zero results feels worse than if there had been no autocomplete at all. The diagram below shows how the three sources merge into one list.

The three sources are not always in stock, so each kind of shortage needs a fallback. New users have no history, so the history source is empty — let the content index and popular queries carry the list, and do not leave an empty "no history yet" slot in the interface. A freshly launched app has no popular queries either, so start with the content index alone and plug popular queries in after two weeks of real search data. And the content index itself must never be faked: with only 50 recipes in the library, the suggestions can only come from what those 50 recipes make possible. Admit that honestly instead of inventing phrases nobody searched for just to fill the list.
Fault tolerance and Chinese input: pinyin, typos, and prefix matching
Chinese search has a problem English search does not. What the user types may not be Chinese characters at all — it may be pinyin, pinyin initials, or a mistyped character. One dish, "braised pork", might be typed as "hongshao rou", as "hsr", or mistyped as "braised pork" with one wrong character. Autocomplete has to recognize all of these inputs and lead them to the same phrase. Without that, autocomplete in a Chinese product is only half built.
Start with pinyin initials. This is the cheapest trick with the fastest payoff: store a pinyin-initial form for every entry — "hsr" for "braised pork", "xhsjd" for "tomato egg stir-fry". When the user types "hsr", match directly against the initials and push the hits up. Initials have a real advantage: typing three letters on a phone is much faster than typing six characters, and once users discover that initials work, they build the habit. Watch out for ambiguity: "hsr" could be "braised pork" or "seafood congee" — rank by popularity and user history, and let the more likely one show first. Ambiguity is nothing to fear; failing to handle it is. Listing every possibility and making the user pick defeats the point of autocomplete, which is to save typing.
Next, typo correction. A user types "braised pork" with one wrong character, or the wrong character inside "tomato". That happens every day. The fix is edit distance: a phrase that differs by one character is treated as a mistyped version of the same phrase and pushed up anyway. But keep the correction restrained: correct a one-character difference only, never two. One character off is almost always a slip of the finger; two characters off may mean the user wanted something else entirely, and forcing the correction would lead them to the wrong place. One more point: let the user see the correction — add a gentle "did you mean: braised pork" after the suggestion instead of silently replacing what they typed. Users want a hint, not to have their input rewritten.
Finally, the trade-off between prefix matching and substring matching. Prefix matching means "find phrases that start with what was typed": type "tomato" and you get "tomato egg stir-fry" and "tomato beef stew", but not "egg tomato soup". Substring matching means "any phrase containing those characters counts", so "egg tomato soup" shows up too. Substring matching recalls more, but it is noisy: the user typed two characters and you hand them ten loosely related items, leaving them unsure which to tap. A safe trade-off is to let autocomplete do prefix matching only, keeping the list clean and every item on topic, and leave substring matching to the full results page, where the user can browse after hitting Enter. Autocomplete exists to be fast, precise, and short — not to be exhaustive.
Interaction details: keyboard, Esc, and keeping the input visible
No matter how accurate the suggestions are, sloppy interaction ruins them. On desktop, the basics are: the up and down arrow keys move the highlight between suggestions, Enter confirms the highlighted one, and Esc closes the suggestion panel. These three keys are habits users bring from every other search box; they need no teaching, and their fingers will find them on their own. If your panel ignores the arrow keys, users will press twice, give up, and switch to the mouse. Clicking works, of course — but keyboard users, who are often the heaviest searchers, will come away feeling the search box is "hard to use".
The rules for closing the panel matter too: Esc closes it, clicking the empty space outside the input closes it, and picking a suggestion dismisses it on its own. The worst failure is a panel that will not go away: the user presses Esc and it stays, clicks outside and it stays, and only another click on the search box makes it leave. A sticky panel makes the search box feel "glued shut", and users will avoid opening it next time. One more rule: when the user deletes everything in the input, the panel should disappear with it. An empty input with a row of suggestions still hanging there looks like a bug.
Mobile has one rule desktop does not: the suggestion panel must not cover the input box. Once the on-screen keyboard pops up, only half the screen is left, and if the panel grows downward from the input, it can easily push the input out of view — the user keeps typing without seeing what they typed. The fix is to let the panel expand just below the input while nudging the page upward so the input stays visible above the keyboard. Another mobile rule is touch-target size: every suggestion needs at least a finger's height of room. Rows packed too tightly lead to mis-taps, and the cost of a mis-tap is landing on the wrong results page and having to go back and search again — a round trip more frustrating than having no autocomplete at all.
Two small touches are worth doing. First, bold the part of each suggestion that matches what the user typed, so they can confirm at a glance that "this is the phrase I meant" without comparing character by character. Second, attach a count to each suggestion, such as "128 recipes", so users know before tapping how much content waits behind it. Neither is hard to build, but they decide whether autocomplete feels like it "understands me" or like it is just filling space.
Performance and cost: cheap methods first, LLM only as a fallback
Autocomplete is the most frequently called feature in the search box — every keystroke can trigger a request — so performance and cost need to be worked out first. The first calculation is the minimum trigger length: 1 character is enough to trigger suggestions in Chinese, while English usually needs 2 letters. One Chinese character already carries a lot of information — the character for "tomato" already narrows the field considerably — while a single English letter matches thousands of words and produces an unreadable list. Set the trigger too low and request volume doubles; set it too high and users type two or three characters without seeing any suggestion and assume autocomplete is broken.
The second calculation is debouncing and caching. Debouncing means not firing a request for every keystroke while the user is typing in a burst — wait until they pause for 150 to 300 milliseconds, then send one request. Typing is a burst of motion; the characters in the middle are just passing through, and only the pause at the end is worth computing. Caching means precomputing and storing the results for the hottest prefixes: the few hundred prefixes searched most each day produce nearly identical suggestion lists, so there is no reason to compute them fresh every time. With just these two measures, a small app can cut autocomplete requests by more than half, and the server will barely feel the load.
The third calculation is the data structure. Autocomplete usually rests on a trie or an inverted index: a trie fits the "find phrases starting with what was typed" pattern, is fast to query, and does not use much memory; an inverted index fits apps that already have a search service, since the existing index can be reused. A small app does not need a separate heavy system just for autocomplete — start with whatever data structure is already at hand, and switch when the volume grows. Overbuilding the architecture early is the most common waste for a small team.
Only then is it time for an LLM. Some teams want a large language model to generate suggestions from day one, but the math has to be done first: every model call costs money and adds a network round trip, and at a trigger rate of once per keystroke, neither the cost nor the latency holds up. The sensible division of labor is this: cheap methods — prefix matching, pinyin, typo correction — do the main work and cover more than 90% of requests; the LLM is only the fallback, called when the three sources return nothing and a zero-result page is imminent, to guess "did you mean…" for that one case. A good guess is a pleasant surprise; a bad guess is just one extra line of suggestions and cannot drag down the whole pipeline. Get the cheap methods right first — only then has the expensive method earned its place.
Iterate with data: watch three numbers, don't guess
Once autocomplete is live, what to change and what to leave alone must come from three numbers, not gut feeling. The first is the suggestion click-through rate: of the people who saw suggestions, how many actually tapped one. A high rate means the suggestions are on target; a low rate means they miss the mark or are ranked wrong. The second is the zero-result rate: the share of all searches that return nothing. The lower the better — much of autocomplete's value shows up here, because users are guided to a phrase with results before they even hit search, so zero results shrink on their own. The third is the zero-result Top list: rank the phrases that returned nothing by frequency, and the top of that list is exactly what users really want but your library does not have. Read it once a week and work through the top entries one by one: if the recipe is missing from the library, add the content; if the phrase is mistyped or the pinyin does not line up, fix the correction; if users are searching for a category you simply do not cover, accept it and do not force a match.
Take the "What's for Dinner" search box and do the math (fictional example): in one month, the search box received focus 10,000 times, and 8,200 of those showed autocomplete suggestions — 82.0%. Of the people who saw suggestions, 5,740 tapped one — 70.0%. After tapping, 4,305 reached the results page — 75.0%. Finally, 1,292 completed the target action — opening a recipe and saving it or starting to cook along — about 30.0%. The funnel chart below shows the same math.

Read this funnel by asking which step loses the most people. Focus to suggestion loses 1,800: users who opened the box and closed it right away, or stopped after a single character — the trigger could be loosened a little. Suggestion to tap loses 2,460, the biggest loss in the funnel, which points at the suggestions themselves: either the ranking is off and the phrase users want sits too low, or the suggestions do not match what was typed and users glance and leave. Tap to results page loses 1,435 — check whether navigation stalls or the results page loads too slowly. Results page to target action loses 3,013, the largest headcount, but this step is not autocomplete's responsibility — how good the recipe page is and how clearly it is written is what matters there. A funnel never hands you the answer; it only tells you which step to investigate first.
Iterate at a pace of one change per week. Fix ranking this week and watch whether the click-through rate moves next week; if it moved, write it down; if it did not, try a different angle. The worst mistake is changing three things at once — trigger length, ranking rules, and panel styling — because when the numbers improve you will not know which change did it. One more habit: keep the zero-result Top list in its own document and update it weekly. Once the top entry is fixed, the list moves on by itself and a new top entry appears — the list never empties, and it is your to-do list.
Three things to do this week
If you can only do three things this week, do them in this order. First, wire up the three sources: popular queries, user history, and the content index — deduplicate, rank with "history first, index second, popular last", and cut the list to 6 to 8 items. Do not worry about pinyin or typo correction yet; get the list working so that typing two characters already shows suggestions. Second, add pinyin initials and one-character typo correction: without those two, autocomplete in a Chinese product is only half built. Third, instrument the three numbers: suggestion click-through rate, zero-result rate, and the zero-result Top list — and start reading them in the first week after launch. With those three done, your search box stops being a spelling test and becomes "found it before you finished typing". Everything after that is the slow work of reading the numbers and changing one thing at a time.
Comments (0)
Related articles
One page should stand up on a phone, a tablet, and a computer. This guide follows MDN's Responsive web design, Using media queries, and the viewport meta reference: fluid HTML, the viewport tag, fluid grids and max-width, images that never burst their container, media query syntax, breakpoints set by content, mobile first, responsive type, testing capability instead of width, and a pre-launch checklist.
localStorage only stores strings and has no indexes. IndexedDB is a real database in the browser: structured data, far larger capacity, indexes, and transactions. Following MDN's Using IndexedDB, IDBDatabase, and IDBObjectStore: the five-step routine, opening, upgrades, keys, indexes, transactions, add versus put, get, cursors, ranges, and multi-tab upgrades.
You already call functions every day; this guide names what you have been doing. Following MDN's Functions, Arrow function expressions, and Rest parameters: declarations versus expressions, parameters and arguments, default values, rest parameters, spread syntax, return values, arrow function shorthand, the this trap, callbacks, and scope.