suggest

fun suggest(countries: List<Country>, query: String, limit: Int = DEFAULT_SUGGESTION_LIMIT): List<Country>(source)

Countries whose name nearly matches query — the "Did you mean …?" fallback when search finds nothing.

Compares the normalized query against each country's name, the words of its name and its aliases, both whole and as a prefix of the same length (so a half-typed name with a typo, "austrai", still finds Australia). Distance is optimal-string-alignment Damerau–Levenshtein, so a transposition ("Germnay") costs one edit, like a substitution. The allowance grows with the query: one edit up to four letters, two up to eight, three beyond — loose enough to catch real typos without flooding a short query with unrelated names.

Numeric queries return nothing: a dial code that matches no country has no near neighbour worth suggesting.

Parameters

limit

Maximum suggestions, closest first.