Search engine
The one idea: an index sorted by importance
Section titled “The one idea: an index sorted by importance”Every place gets a static importance score:
importance = feature weight + population score| Feature | Weight |
|---|---|
| Country | 1600 |
| State (ADM1) | 1450 |
| Capital | 1300 |
| Airport | 1250 |
| State capital | 1200 |
| Island | 1150 |
| District capital | 1100 |
| Other town or village | 1000 |
| Other admin area, mountain, park | 900 |
| Buildings, hotels | 850 |
| Rivers, roads, forests | 800 |
The population score adds about 100 per ×10 (1,000 → 410, 1 million → 710, 10 million → 810).
The full-text index place_search stores places in importance order. Asking for “the first 200 matches” therefore returns the 200 most important matches, and the database stops there. A common prefix like sa costs the same as santorini.
What happens on a cache miss
Section titled “What happens on a cache miss”- Candidates (1 D1 batch): up to 200 name matches and 100 alias matches per region, plus up to 50 exact-name matches. In
automode there are two regions, India and the world. - Score each candidate:
match tier + importance, plus 500 if it is in India and the mode isauto. - Typo recovery (1 D1 batch, only if needed): runs only when no notable place matched. It reads the 300 most important places sharing the first two letters and keeps those within 1–2 edits.
- Hydrate (1 D1 query): joins names only for the page being returned.
| Match tier | Points | Example |
|---|---|---|
| Exact name | 1200 | goa → Goa |
| Exact alias (3+ letters) | 1100 | bombay → Mumbai, nyc |
| Name starts with query | 900 | mumb → Mumbai |
| Every word starts a name word | 500 | saint p → Saint Petersburg |
| Alias starts with query | 200 | |
| One-letter typo (only when recovery ran) | 600 | mumbia → Mumbai |
| Two-letter typo | always last |
Many tenants at once
Section titled “Many tenants at once”- Workers: each request has its own isolate. Requests never wait for each other here.
- D1: one database runs one query at a time. Every tenant shares this queue, so query time is what matters.
- Our numbers (full 13.47M dataset, local, no cache, people typing 34 destinations letter by letter):
| Before | Now | |
|---|---|---|
| Average DB time per search | 285 ms | 6.6 ms |
| Slowest 1% | 4.6 s | 17 ms |
| One database’s ceiling | ~3 searches/s | ~150 searches/s |
- KV cache answers repeats (
go,goa) with zero DB work, so real capacity is higher. - If it is ever not enough: turn on D1 read replication (see Roadmap). A Cloudflare Queue would not help: queues are for background jobs, not instant answers.
Text handling
Section titled “Text handling”- Case, accents and punctuation are ignored.
Łódźmatcheslodz. - Native scripts work:
मुंबई,சென்னை. - One-letter words are checked in code, not in the index.
- Digit-only queries (PIN codes) return nothing. GeoNames has no postal data.
Known gaps
Section titled “Known gaps”- Unpopulated landmarks rank low:
everestshows small towns named Everest first. - Typos in the first two letters are not recovered.
- Very common words (
lake) cost up to about 40 ms of DB time.