Fuzzy autocomplete search across products and categories.
Returns ranked autocomplete suggestions matching a search term across published products and categories. Results are cached in Nitro server storage for 5 minutes per unique query.Method:GET Path:/api/search/suggest Caching: 5 minutes in-memory (Nitro storage)
Search is powered by a lightweight scoring function that ranks results by prefix match (score 100) and substring match (score 50). Diacritics are normalised so that "gran" matches "Gran Formato" and "Gràfic".
The scoring function normalises both the search term and candidate titles to lowercase NFD form before comparing:
function score(title: string, term: string): number { const t = normText(title) // lowercase + remove diacritics if (!t) return 0 if (t.startsWith(term)) return 100 // prefix match if (t.includes(term)) return 50 // substring match return 0 // no match}
Results with score 0 are excluded. Within the same score tier, results are sorted alphabetically by title. Products appear before categories in the final merged list.