geocoder-core
Address geocoding and autocomplete in Rust, embedded in your process. A faithful port of addok, the engine behind the French national address API, with a memory-mapped index instead of Redis.
- 🎯 Same answers as the BAN API: addok 1.3 + addok-fr + addok-france, validated function by function against the Python code.
- ⚡ Fast and light: about 3 ms per query; the index is memory mapped, so serving France, Luxembourg and Belgium takes ~60 MB of private memory.
- 🌍 Country profiles: France (BAN), Luxembourg (BD-Adresses), Belgium (BeST Address, in French, Dutch and German).
- 🧩 No server: build an index file, open it, search. The HTTP API
(
geocoder-api) is a separate binary built on this crate.
Quick start
[]
= { = "0.2", = false }
use ;
// Build once from the BAN export (written next to the target, then renamed;
// flate2 is only needed by this example).
let file = open?;
let reader = new;
import?;
// Open (memory mapped) and query.
let geocoder = open?;
for result in geocoder.search
let nearest = geocoder.reverse;
Geocoder is Send + Sync: share it behind an Arc and query from any
thread.
Countries
| Profile | Source | Licence | Documents |
|---|---|---|---|
fr |
BAN addok export | Etalab 2.0 | 2.5 M (3.3 GB index) |
lu |
BD-Adresses | CC0 | 9 k |
be |
BeST Address (3 regions) | CC BY 4.0 | 147 k |
Source::Bano reads BANO files and profile::by_name("default") gives plain
addok, a starting point for another country: a Profile overrides only what
differs (query cleanup, housenumbers, synonyms, phonetics, labels, filters).
The profile name and version are stored in the index: opening an index built by an incompatible version fails instead of returning wrong results.
France: an index can carry a CEDEX table ([postal::CedexTable], built with
[readers::cedex] and IndexBuilder::set_cedex), in an optional section
older readers skip. A query with a CEDEX line ("92074 Paris La Défense
Cedex") is then searched as the municipality it serves, and its results
carry the line as written (SearchResult::postal, postal_label); without
a table the line is still given back.
Building indexes
Building takes memory: about 5 GB and 6 minutes for France, 4 GB for
Belgium, seconds for Luxembourg. Searching does not. The cli feature (on
by default) adds two binaries:
Tracing
Searches, reverse lookups, index opening and builds run in
tracing spans (INFO): geocoder.search (with
geocoder.collect and geocoder.rank), geocoder.reverse,
geocoder.open, geocoder.import (with geocoder.write). Their fields
describe a query's shape, never its text: token counts, the collector that
settled it, the documents scored and the time spent scoring them, the
results. Nothing is recorded without a subscriber; with Sentry's or
OpenTelemetry's, they show up under the caller's span. Calling from
spawn_blocking, carry that span (and the Sentry hub) into the closure,
or they start traces of their own.
Licence
MIT. Ports addok, addok-fr and addok-france (MIT, Etalab / DINUM). The address data keep their own licences: credit their producers.