Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation for new Python frontend #3178

Merged
merged 17 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set (DOC_SOURCES
develop
api
customize
library
index.md
extra.css
styles.css
Expand All @@ -25,10 +26,10 @@ endforeach()
ADD_CUSTOM_TARGET(doc
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bash2md.sh ${PROJECT_SOURCE_DIR}/vagrant/Install-on-Ubuntu-20.sh ${CMAKE_CURRENT_BINARY_DIR}/appendix/Install-on-Ubuntu-20.md
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bash2md.sh ${PROJECT_SOURCE_DIR}/vagrant/Install-on-Ubuntu-22.sh ${CMAKE_CURRENT_BINARY_DIR}/appendix/Install-on-Ubuntu-22.md
COMMAND PYTHONPATH=${PROJECT_SOURCE_DIR} mkdocs build -d ${CMAKE_CURRENT_BINARY_DIR}/../site-html -f ${CMAKE_CURRENT_BINARY_DIR}/../mkdocs.yml
COMMAND mkdocs build -d ${CMAKE_CURRENT_BINARY_DIR}/../site-html -f ${CMAKE_CURRENT_BINARY_DIR}/../mkdocs.yml
)

ADD_CUSTOM_TARGET(serve-doc
COMMAND PYTHONPATH=${PROJECT_SOURCE_DIR} mkdocs serve
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMAND mkdocs serve -f ${CMAKE_CURRENT_BINARY_DIR}/../mkdocs.yml
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
2 changes: 1 addition & 1 deletion docs/admin/Deployment.md → docs/admin/Deployment-PHP.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Deploying Nominatim
# Deploying Nominatim using the PHP frontend

The Nominatim API is implemented as a PHP application. The `website/` directory
in the project directory contains the configured website. You can serve this
Expand Down
115 changes: 115 additions & 0 deletions docs/admin/Deployment-Python.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Deploying the Nominatim Python frontend

The Nominatim can be run as a Python-based web application. You have the
choice between [Falcon](https://falcon.readthedocs.io/en/stable/)
and [Starlette](https://www.starlette.io/) as the ASGI framework.

This section gives a quick overview on how to configure Nginx to server
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to serve

Nominatim. Please refer to the documentation of
[Nginx](https://nginx.org/en/docs/) for background information on how to configure it.

!!! Note
Throughout this page, we assume that your Nominatim project directory is
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"that" in this and next line can be removed

located in `/srv/nominatim-project` and that you have installed Nominatim
using the default installation prefix `/usr/local`. If you have put it
somewhere else, you need to adjust the commands and configuration
accordingly.

We further assume that your web server runs as user `www-data`. Older
versions of CentOS may still use the user name `apache`. You also need
to adapt the instructions in this case.

### Installing the required packages

The recommended way to deploy Python ASGI application is to run
Copy link
Collaborator

@mtmail mtmail Aug 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deploy the

the ASGI runner (uvicorn)[https://uvicorn.org/]
together with (gunicorn)[https://gunicorn.org/] HTTP server. We use
Falcon here as the web framework.

Create a virtual environment for the Python packages and install the necessary
dependencies:

``` sh
sudo apt install virtualenv
virtualenv /srv/nominatim-venv
/srv/nominatim-venv/bin/pip install SQLAlchemy PyICU psycopg[binary]\
psycopg2-binary python-dotenv PyYAML falcon uvicorn gunicorn
```

### Setting up Nominatim as a systemd job

Next you need to set up the application that serves Nominatim. This is
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

section starts with "set up the application" but ends "this sets the service up". I think it should be service

easiest done with a systemd job.

Create the following file `/etc/systemd/system/nominatim.service`:

``` systemd
[Unit]
Description=Nominatim running as a gunicorn application
After=network.target
Requires=nominatim.socket

[Service]
Type=simple
Environment="PYTHONPATH=/usr/local/lib/nominatim/lib-python/"
User=www-data
Group=www-data
WorkingDirectory=/srv/nominatim-project
ExecStart=/srv/nominatim-venv/bin/gunicorn -b unix:/run/nominatim.sock -w 14 -k uvicorn.workers.UvicornWorker nominatim.server.falcon.server:run_wsgi
ExecReload=/bin/kill -s HUP $MAINPID
StandardOutput=append:/ssd/nominatim/log/gunicorn.log
StandardError=inherit
PrivateTmp=true
TimeoutStopSec=5
KillMode=mixed

[Install]
WantedBy=multi-user.target
```

Make the new service known to systemd and start it:

``` sh
sudo systemctl daemon-reload
sudo systemctl enable nominatim
sudo systemctl start nominatim
```

This sets the service up, so that Nominatim is automatically started
on reboot.

### Configuring nginx

To make the service available to the world, you need to proxy it through
nginx. Add the following definition to the default configuration:

``` nginx
upstream nominatim_service {
server unix:/run/nominatim.sock fail_timeout=0;
}

server {
listen 80;
listen [::]:80;

root /var/www/html;
index /search;

location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
proxy_pass http://nominatim_service;
}
}
```

Reload nginx with

```
sudo systemctl reload nginx
```

and you should be able to see the status of your server under
`http://localhost/status`.
66 changes: 55 additions & 11 deletions docs/admin/Import.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,26 +254,70 @@ successfully.
nominatim admin --check-database
```

Now you can try out your installation by running:
Now you can try out your installation by executing a simple query on the
command line:

``` sh
nominatim search --query Berlin
```

or, when you have a reverse-only installation:

``` sh
nominatim reverse --lat 51 --lon 45
```

If you want to run Nominatim as a service, you need to make a choice between
running the traditional PHP frontend or the new experimental Python frontend.
Make sure you have installed the right packages as per
[Installation](Installation.md#software).

#### Testing the PHP frontend

You can run a small test server with the PHP frontend like this:

```sh
nominatim serve
```

This runs a small test server normally used for development. You can use it
to verify that your installation is working. Go to
`http://localhost:8088/status.php` and you should see the message `OK`.
You can also run a search query, e.g. `http://localhost:8088/search.php?q=Berlin`.
Go to `http://localhost:8088/status.php` and you should see the message `OK`.
You can also run a search query, e.g. `http://localhost:8088/search.php?q=Berlin`
or, for reverse-only installations a reverse query,
e.g. `http://localhost:8088/reverse.php?lat=27.1750090510034&lon=78.04209025`.

Do not use this test server in production.
To run Nominatim via webservers like Apache or nginx, please continue reading
[Deploy the PHP frontend](Deployment-PHP.md).

#### Testing the Python frontend

To run the test server against the Python frontend, you must choose a
web framework to use, either starlette or falcon. Make sure the appropriate
packages are installed. Then run

``` sh
nominatim serve --engine falcon
```

or

``` sh
nominatim serve --engine starlette
```

Go to `http://localhost:8088/status.php` and you should see the message `OK`.
You can also run a search query, e.g. `http://localhost:8088/search.php?q=Berlin`
or, for reverse-only installations a reverse query,
e.g. `http://localhost:8088/reverse.php?lat=27.1750090510034&lon=78.04209025`.

Note that search query is not supported for reverse-only imports. You can run a
reverse query, e.g. `http://localhost:8088/reverse.php?lat=27.1750090510034&lon=78.04209025`.
Do not use this test server in production.
To run Nominatim via webservers like Apache or nginx, please continue reading
[Deploy the Python frontend](Deployment-Python.md).

To run Nominatim via webservers like Apache or nginx, please read the
[Deployment chapter](Deployment.md).

## Adding search through category phrases
## Enabling search by category phrases

If you want to be able to search for places by their type through
If you want to be able to search for places by their type using
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd skip the "If you want"

[special phrases](https://wiki.openstreetmap.org/wiki/Nominatim/Special_Phrases)
you also need to import these key phrases like this:

Expand Down
13 changes: 3 additions & 10 deletions docs/admin/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ For running Nominatim:
* [PyICU](https://pypi.org/project/PyICU/)
* [PyYaml](https://pyyaml.org/) (5.1+)
* [datrie](https://github.com/pytries/datrie)

When running the PHP frontend:
* [PHP](https://php.net) (7.3+)
* PHP-pgsql
* PHP-intl (bundled with PHP)
Expand Down Expand Up @@ -83,7 +85,7 @@ Take into account that the OSM database is growing fast.
Fast disks are essential. Using NVME disks is recommended.

Even on a well configured machine the import of a full planet takes
around 2 days. On traditional spinning disks, 7-8 days are more realistic.
around 2 days. When using traditional SSDs, 4-5 days are more realistic.

## Tuning the PostgreSQL database

Expand Down Expand Up @@ -115,15 +117,6 @@ you might consider setting:
and even reduce `autovacuum_work_mem` further. This will reduce the amount
of memory that autovacuum takes away from the import process.

For the initial import, you should also set:

fsync = off
full_page_writes = off

Don't forget to re-enable them after the initial import or you risk database
corruption.


## Downloading and building Nominatim

### Downloading the latest release
Expand Down
88 changes: 62 additions & 26 deletions docs/api/Details.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

Show all details about a single place saved in the database.

This API endpoint is meant for visual inspection of the data in the database
and is meant for use with [Nominatim-UI](https://github.com/osm-search/nominatim-ui/).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second "is meant" can be removed

The parameters of the endpoint and the output may change occasionally between
versions of Nominatim. Do not rely on the output in scripts or applications.


!!! warning
The details page exists for debugging only. You may not use it in scripts
or to automatically query details about a result.
The details endpoint at https://nominatim.openstreetmap.org
may not used in scripts or bots at all.
See [Nominatim Usage Policy](https://operations.osmfoundation.org/policies/nominatim/).


## Parameters

The details API supports the following two request formats:

Expand All @@ -35,59 +40,90 @@ for a place is different between Nominatim installation (servers) and
changes when data gets reimported. Therefore it cannot be used as
a permanent id and shouldn't be used in bug reports.

!!! danger "Deprecation warning"
The API can also be used with the URL
`https://nominatim.openstreetmap.org/details.php`. This is now deprecated
and will be removed in future versions.


Additional optional parameters are explained below.
## Parameters

This section lists additional optional parameters.

### Output format

* `json_callback=<string>`
| Parameter | Value | Default |
|-----------| ----- | ------- |
| json_callback | function name | _unset_ |

Wrap JSON output in a callback function (JSONP) i.e. `<string>(<json>)`.
When given, then JSON output will be wrapped in a callback function with
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"When set" might work to avoid using "given" twice

the given name. See [JSONP](https://en.wikipedia.org/wiki/JSONP) for more
information.

* `pretty=[0|1]`
| Parameter | Value | Default |
|-----------| ----- | ------- |
| pretty | 0 or 1 | 0 |

Add indentation to make it more human-readable. (Default: 0)
`[PHP-only]` Add indentation to the output to make it more human-readable.


### Output details

* `addressdetails=[0|1]`
| Parameter | Value | Default |
|-----------| ----- | ------- |
| addressdetails | 0 or 1 | 0 |

Include a breakdown of the address into elements. (Default: 0)
When set to 1, include a breakdown of the address into elements.

* `keywords=[0|1]`
| Parameter | Value | Default |
|-----------| ----- | ------- |
| keywords | 0 or 1 | 0 |

Include a list of name keywords and address keywords (word ids). (Default: 0)
When set to 1, include a list of name keywords and address keywords
in the result.

* `linkedplaces=[0|1]`
| Parameter | Value | Default |
|-----------| ----- | ------- |
| linkedplaces | 0 or 1 | 1 |

Include a details of places that are linked with this one. Places get linked
Include details of places that are linked with this one. Places get linked
together when they are different forms of the same physical object. Nominatim
links two kinds of objects together: place nodes get linked with the
corresponding administrative boundaries. Waterway relations get linked together with their
members.
(Default: 1)

* `hierarchy=[0|1]`
| Parameter | Value | Default |
|-----------| ----- | ------- |
| hierarchy | 0 or 1 | 0 |

Include details of places lower in the address hierarchy.

`[Python-only]` will only return properly parented places. These are address
or POI-like places that reuse the address of their parent street or place.

Include details of places lower in the address hierarchy. (Default: 0)
| Parameter | Value | Default |
|-----------| ----- | ------- |
| group_hierarchy | 0 or 1 | 0 |

* `group_hierarchy=[0|1]`
When set to 1, the output of the address hierarchy will be
grouped by type.

For JSON output will group the places by type. (Default: 0)
| Parameter | Value | Default |
|-----------| ----- | ------- |
| polygon_geojson | 0 or 1 | 0 |

* `polygon_geojson=[0|1]`

Include geometry of result. (Default: 0)
Include geometry of result.

### Language of results

* `accept-language=<browser language string>`
| Parameter | Value | Default |
|-----------| ----- | ------- |
| accept-language | browser language string | content of "Accept-Language" HTTP header |

Preferred language order for showing result, overrides the value
specified in the "Accept-Language" HTTP header.
Either use a standard RFC2616 accept-language string or a simple
comma-separated list of language codes.
Preferred language order for showing search results. This may either be
a simple comma-separated list of language codes or have the same format
as the ["Accept-Language" HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language).


## Examples
Expand Down
Loading