]> git.openstreetmap.org Git - nominatim.git/blob - docs/develop/Ranking.md
reorganize ranks of high-level place types
[nominatim.git] / docs / develop / Ranking.md
1 # Place Ranking in Nominatim
2
3 Nominatim uses two metrics to rank a place: search rank and address rank.
4 Both can be assigned a value between 0 and 30. They serve slightly
5 different purposes, which are explained in this chapter.
6
7 ## Search rank
8
9 The search rank describes the extent and importance of a place. It is used
10 when ranking search result. Simply put, if there are two results for a
11 search query which are otherwise equal, then the result with the _lower_
12 search rank will be appear higher in the result list.
13
14 Search ranks are not so important these days because many well-known
15 places use the Wikipedia importance ranking instead.
16
17 The following table gives an overview of the kind of features that Nominatim
18 expects for each rank:
19
20 rank   | typical place types             | extent
21 -------|---------------------------------|-------
22 1-3    | oceans, continents              | -
23 4      | countries                       | -
24 5-9    | states, regions, provinces      | -
25 10-12  | counties                        | -
26 13-16  | cities, municipalities, islands | 15 km
27 17-18  | towns, boroughs                 | 4 km
28 19     | villages, suburbs               | 2 km
29 20     | hamlets, farms, neighbourhoods  |  1 km
30 21-25  | isolated dwellings, city blocks | 500 m
31
32 The extent column describes how far a feature is assumed to reach when it
33 is mapped only as a point. Larger features like countries and states are usually
34 available with their exact area in the OpenStreetMap data. That is why no extent
35 is given.
36
37 ## Address rank
38
39 The address rank describes where a place shows up in an address hierarchy.
40 Usually only administrative boundaries and place nodes and areas are
41 eligible to be part of an address. Places that should not appear in the
42 address must have an address rank of 0.
43
44 The following table gives an overview how ranks are mapped to address parts:
45
46  rank        | address part
47 -------------|-------------
48  1-3         | _unused_
49  4           | country
50  5-9         | state
51  10-12       | county
52  13-16       | city
53  17-21       | suburb
54  22-24       | neighbourhood
55  25          | squares, farms, localities
56  26-27       | street
57  28-30       | POI/house number
58
59 The country rank 4 usually doesn't show up in the address parts of an object.
60 The country is determined indirectly from the country code.
61
62 Ranks 5-24 can be assigned more or less freely. They make up the major part
63 of the address.
64
65 Rank 25 is also an addressing rank but it is special because while it can be
66 the parent to a POI with an addr:place of the same name, it cannot be a parent
67 to streets. Use it for place features that are technically on the same level
68 as a street (e.g. squares, city blocks) or for places that should not normally
69 appear in an address unless explicitly tagged so (e.g place=locality which
70 should be uninhabited and as such not addressable).
71
72 The street ranks 26 and 27 are handled slightly differently. Only one object
73 from these ranks shows up in an address.
74
75 For POI level objects like shops, buildings or house numbers always use rank 30.
76 Ranks 28 is reserved for house number interpolations. 29 is for internal use
77 only.
78
79 ## Rank configuration
80
81 Search and address ranks are assigned to a place when it is first imported
82 into the database. There are a few hard-coded rules for the assignment:
83
84  * postcodes follow special rules according to their length
85  * boundaries that are not areas and railway=rail are dropped completely
86  * the following are always search rank 30 and address rank 0:
87     * highway nodes
88     * landuse that is not an area
89
90 Other than that, the ranks can be freely assigned via the JSON file
91 defined with `CONST_Address_Level_Config` according to their type and
92 the country they are in.
93
94 The address level configuration must consist of an array of configuration
95 entries, each containing a tag definition and an optional country array:
96
97 ```
98 [ {
99     "tags" : {
100       "place" : {
101         "county" : 12,
102         "city" : 16,
103       },
104       "landuse" : {
105         "residential" : 22,
106         "" : 30
107       }
108     }
109   },
110   {
111     "countries" : [ "ca", "us" ],
112     "tags" : {
113       "boundary" : {
114         "administrative8" : 18,
115         "administrative9" : 20
116       },
117       "landuse" : {
118         "residential" : [22, 0]
119       }
120     }
121   }
122 ]
123 ```
124
125 The `countries` field contains a list of countries (as ISO 3166-1 alpha 2 code)
126 for which the definition applies. When the field is omitted, then the
127 definition is used as a fallback, when nothing more specific for a given
128 country exists.
129
130 `tags` contains the ranks for key/value pairs. The ranks can be either a
131 single number, in which case they are the search and address rank, or an array
132 of search and address rank (in that order). The value may be left empty.
133 Then the rank is used when no more specific value is found for the given
134 key.
135
136 Countries and key/value combination may appear in multiple definitions. Just
137 make sure that each combination of country/key/value appears only once per
138 file. Otherwise the import will fail with a UNIQUE INDEX constraint violation
139 on import.
140