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