# Ranking

> How text relevance, importance and focus points decide the order of results.

## 1. Words, not syntax

The text is split into words of letters and digits, lower-cased, and capped at 12 words. The words are looked up in the term dictionary of the `.glx` file. User input has no query syntax.

## 2. All words first, then most of them

Every word is required first. If that finds fewer than `size` places, about three quarters of the words (rounded up) are required.

| Words | Required after relaxing |
| --- | --- |
| 1–3 | all |
| 4 | 3 |
| 5 | 4 |
| 8 | 6 |

A word that is in more than one place in a thousand is a common word. Common words do not decide a relaxed match.

## 3. Text score plus importance

Each place gets this score:

```text
BM25 text score + importance * weight
```

`importance` is a 0–1 value from the geolith build. The posting lists hold BM25 statistics, so the score comes from the index. `layers` and `boundary.country` filters apply before place records are read. `geocoding.query.ranking` is `importance`.

## 4. Focus points

With `focus.point.lat` and `focus.point.lon`, boxes of half-width 0.05°, 0.25° and 0.5° around the point are searched in turn. The search stops at the first box that holds `size` places. Nearby places come first. Each gets a distance boost of up to +5 that halves every 10 km. Each result has `distance` in kilometres. If the boxes hold fewer than `size` places, the global ranking fills the rest. `geocoding.query.ranking` is then `importance+distance`.

## 5. Autocomplete

The last word matches as a prefix. See [Autocomplete](/search/api/autocomplete) for the details.

## Confidence

`confidence` is the share of query words found in the place's text, from 0 to 1. With autocomplete, the last word counts when a word starts with it.
