Greek shoppers type the same product in at least four ways:

  • Αντηλιακό (with the accent)
  • αντηλιακο (no accent, because it costs an extra tap)
  • antiliako (Greeklish, keyboard left on Latin)
  • antilliako (Greeklish with a doubled letter, typed on a phone)

And they mix scripts in one query: σαμπουάν klorane (product type in Greek, brand in Latin). A search box that compares strings with LIKE '%...%' finds only the first one. The shopper sees «no results», goes back to Google and clicks the next shop.

This is how we solved it for the storefronts of Nextcommerce, the ecommerce platform we build for Greek shops. No external search service: about 150 lines of TypeScript inside the API.

The idea: reduce everything to a sound skeleton

Greeklish has no standard. The sound «i» can be written η, ι, υ, ει, οι in Greek, and i, h, y, ei, oi in Latin. Instead of trying to transliterate «correctly», we throw information away on purpose: every product name and every query is reduced to a lowercase Latin skeleton where all spellings of the same sound collapse into one letter.

Then we compare skeletons.

Αντηλιακό → adiliako αντηλιακο → adiliako antiliako → adiliako antilliako → adiliako Αφρόλουτρο KORRES → afrolutro kores afroloutro korres → afrolutro kores Μπουφάν → vufan boufan → vufan Χυμός → ximos xymos → ximos chimos → ximos 

(That output is from running the function below, not made up.)

The skeleton function

Order matters. Greek digraphs first (ου, μπ, ντ...), then single Greek letters, then the Greeklish/English digraphs, then doubled letters collapse.

const GREEK_PAIRS: [RegExp, string][] = [ [/ου/g, 'u'], [/αι/g, 'e'], [/ει/g, 'i'], [/οι/g, 'i'], [/υι/g, 'i'], [/αυ/g, 'av'], [/ευ/g, 'ev'], [/μπ/g, 'b'], [/ντ/g, 'd'], [/γκ/g, 'g'], [/γγ/g, 'g'], [/τσ/g, 'ts'], [/τζ/g, 'tz'], ]; const GREEK: Record<string, string> = { α: 'a', β: 'v', γ: 'g', δ: 'd', ε: 'e', ζ: 'z', η: 'i', θ: 'th', ι: 'i', κ: 'k', λ: 'l', μ: 'm', ν: 'n', ξ: 'x', ο: 'o', π: 'p', ρ: 'r', σ: 's', τ: 't', υ: 'i', φ: 'f', χ: 'x', ψ: 'ps', ω: 'o', }; // Greeklish and English spellings brought to the same skeleton. const LATIN_PAIRS: [RegExp, string][] = [ [/ch|kh/g, 'x'], [/ph/g, 'f'], [/ou|oy/g, 'u'], [/ei|oi/g, 'i'], [/ai/g, 'e'], [/au/g, 'av'], [/eu/g, 'ev'], [/mp/g, 'b'], [/nt/g, 'd'], [/gk|gg/g, 'g'], [/ks|cs/g, 'x'], [/w/g, 'o'], [/y/g, 'i'], [/(?<!t)h/g, 'i'], [/c|q/g, 'k'], [/b/g, 'v'], ]; export function searchSkeleton(s: string): string { let t = s .toLowerCase() .normalize('NFD') .replace(/[̀-ͯ]/g, '') // strip accents .replace(/ς/g, 'σ'); // final sigma for (const [re, to] of GREEK_PAIRS) t = t.replace(re, to); t = t.replace(/[α-ω]/g, (c) => GREEK[c] ?? c); for (const [re, to] of LATIN_PAIRS) t = t.replace(re, to); return t .replace(/([a-z])\1+/g, '$1') // «kremma» → «krema» .replace(/[^a-z0-9]+/g, ' ') .trim(); } 

A few choices worth explaining:

  • μπ → b → v. In Greek β sounds like «v» and μπ like «b», but shoppers write boufan and mpoufan for μπουφάν. Mapping both b and β to v makes all three meet.
  • h → i, except after t. Greeklish writers use h for η (anthliako), but th is θ. The lookbehind keeps th intact.
  • w → o. Many people type ω as w because it looks the same.
  • Doubled letters collapse. Greek spelling doubles letters (Κορρές), people don't (kores), or they double them by accident on a phone.

Typos: edit distance with an early exit

The skeleton handles spelling variants. Real typos (antliako, antiliko) need a fuzzy comparison. We use Levenshtein distance with a cap, and bail out as soon as a row of the matrix can no longer come in under the cap:

function within(a: string, b: string, max: number): boolean { if (Math.abs(a.length - b.length) > max) return false; let prev = Array.from({ length: b.length + 1 }, (_, i) => i); for (let i = 1; i <= a.length; i++) { const cur = [i]; let best = i; for (let j = 1; j <= b.length; j++) { cur[j] = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1)); if (cur[j] < best) best = cur[j]; } if (best > max) return false; // nothing in this row can recover prev = cur; } return prev[b.length] <= max; } 

The allowed distance depends on the word length: one mistake for words of 4 to 6 letters, two for 7 or more, none under 4. Short words with a typo allowed match almost anything.

Scoring words

Every word of the query has to match something in the product, or the product is out. Each word gets a score, and the product's score is the sum:

function wordScore(tok: string, words: string[], key: string): number { let best = 0; for (const w of words) { if (w === tok) return 4; // exact word if (w.startsWith(tok)) best = Math.max(best, 3); // prefix: «antil» while typing } if (best) return best; if (tok.length >= 3 && key.includes(tok)) return 2; // inside a word if (tok.length < 4) return 0; const max = tok.length >= 7 ? 2 : 1; // typo budget for (const w of words) { if (w.length < 3) continue; if (within(tok, w, max) || (w.length > tok.length && within(tok, w.slice(0, tok.length), max))) return 1; } return 0; } 

Ties are broken by the shorter product name, so Κορρές Αφρόλουτρο ranks above Κορρές Αφρόλουτρο Σετ Δώρου 3 τεμ. for the query afroloutro korres.

Barcodes go first

In a pharmacy, a customer holding an empty box types the number under the bars. That should land on exactly one product, so codes are checked before any fuzzy matching:

const raw = q.trim().toLowerCase(); const codeHits = /^[\w-]{4,}$/.test(raw) ? entries.filter((e) => e.codes.split(' ').includes(raw)) : []; if (codeHits.length) return codeHits.map((e) => e.id); 

codes holds the product's SKU, barcode (EAN) and MPN.

Why no Elasticsearch

Each store searches only its own catalogue. So per store we load the products once, compute the skeletons, and keep them in memory for 60 seconds:

const TTL_MS = 60_000; const cache = new Map<string, { at: number; entries: Entry[] }>(); 

A search is then a loop over an array in memory. There is no LIKE scan on the database, no second copy of the catalogue in another service that has to stay in sync, and no extra bill. The search returns product ids, best first, and the normal product query (prices, stock, filters) runs on those ids. Shoppers search the same data the shop sells from.

The trade-off is honest: this is a linear scan, and a minute-old cache means a product added just now shows up in search within a minute. For one store's catalogue that is fine. For a marketplace with millions of products it would not be.

What it doesn't do

  • It doesn't translate. shampoo becomes siavo, σαμπουάν becomes savuan. Different words, no match. Synonyms would need a list.
  • ευ is ambiguous. In Greek it sounds «ev» or «ef» depending on the next letter. We map it to ev, so efxaristo vs ευχαριστώ matches only through the typo budget (distance 1), not through the skeleton.
  • It can only find what the catalogue says. If the title leaves out the word people use, no amount of fuzziness fills the gap.

One more thing: log what people search

Every search is recorded, and the storefront shows «popular searches» from the last six months. For the shop owner that list is free market research: a frequent search for a brand they don't stock is a buying decision.

We are TWENTYONE, a web development team in Athens. We built this for Nextcommerce, our ecommerce platform for Greek shops.