CountrySearchEngine

Ranked, accent-insensitive, purely local country search.

Matching is deterministic and allocation-light: the country fields are normalized once when the dataset is built, so a query does one pass over the candidate list with only substring comparisons. That is fast enough to run synchronously on every keystroke for the full 236-country dataset — there is deliberately no debounce on local search, because the sub-millisecond filter makes the list feel immediate.

Ranking

Results are ordered by match quality first and country name second:

RankMatch
0Country name equals the query
1Country name starts with the query
2ISO alpha-2 or alpha-3 equals the query
3Dial code equals the query
4Country name contains the query
5An alternative name contains the query
6ISO alpha-2 or alpha-3 starts with the query
7Dial code starts with the query

The last two tiers are partial-input fallbacks so a half-typed code ("25", "ke") still surfaces something, without ever outranking a real name or exact-code match.

Ties break on Country.displayName so the same query always produces the same order.

Functions

Link copied to clipboard
fun search(countries: List<Country>, query: String, fields: Set<CountrySearchField> = CountrySearchField.All, minQueryLength: Int = 1): List<CountryMatch>

Filters and ranks countries against query.

Link copied to clipboard
fun suggest(countries: List<Country>, query: String, limit: Int = DEFAULT_SUGGESTION_LIMIT): List<Country>

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