docs: improve contents listing

This commit is contained in:
Sarah Hoffmann 2024-09-10 20:36:27 +02:00
parent f52212abbd
commit fe0ade81f5
5 changed files with 50 additions and 14 deletions

View File

@ -1,5 +1,3 @@
### Nominatim API
!!! Attention !!! Attention
The current version of Nominatim implements two different search frontends: The current version of Nominatim implements two different search frontends:
the old PHP frontend and the new Python frontend. They have a very similar the old PHP frontend and the new Python frontend. They have a very similar

View File

@ -1,11 +1,13 @@
# Configuration # Configuration
When using Nominatim through the library, it can be configured in exactly When using Nominatim through the library, it can be configured in exactly
the same way as when running as a service. This means that you should have the same way as when running as a service. You may instantiate the library
created a [project directory](../admin/Import.md#creating-the-project-directory) against the [project directory](../admin/Import.md#creating-the-project-directory)
which contains all files belonging to the Nominatim instance. It can also contain of your Nominatim installation. It contains all files belonging to the
an `.env` file with configuration options. Setting configuration parameters Nominatim instance. This may include an `.env` file with configuration options.
via environment variables works as well. Setting configuration parameters via environment variables works as well.
Alternatively to using the operating system's environment, a set of
configuration parameters may also be passed to the Nomiantim API object.
Configuration options are resolved in the following order: Configuration options are resolved in the following order:

View File

@ -34,7 +34,7 @@ To install the package from the source tree directly, run:
Usually you would want to run this in a virtual environment. Usually you would want to run this in a virtual environment.
### A simple search example ## A simple search example
To query the Nominatim database you need to first set up a connection. This To query the Nominatim database you need to first set up a connection. This
is done by creating an Nominatim API object. This object exposes all the is done by creating an Nominatim API object. This object exposes all the
@ -88,7 +88,7 @@ implementations. The documentation itself will usually refer only to
available only for the synchronous or asynchronous version, this will be available only for the synchronous or asynchronous version, this will be
explicitly mentioned. explicitly mentioned.
### Defining which database to use ## Defining which database to use
The [Configuration](../admin/Import.md#configuration-setup-in-env) The [Configuration](../admin/Import.md#configuration-setup-in-env)
section explains how Nominatim is configured using the section explains how Nominatim is configured using the
@ -103,7 +103,41 @@ have normally created a [project directory](../admin/Import.md#creating-the-proj
which stores the various configuration and customization files that Nominatim which stores the various configuration and customization files that Nominatim
needs. You may pass the location of the project directory to your needs. You may pass the location of the project directory to your
'Nominatim API class' constructor and it will read the .env file in the 'Nominatim API class' constructor and it will read the .env file in the
directory and set the configuration accordingly. directory and set the configuration accordingly. Here is the simple search
example, using the configuration from a pre-defined project directory in
`/srv/nominatim-project`:
!!! example
=== "NominatimAPIAsync"
``` python
import asyncio
import nominatim_api as napi
async def search(query):
async with napi.NominatimAPIAsync('/srv/nominatim-project') as api:
return await api.search(query)
results = asyncio.run(search('Brugge'))
if not results:
print('Cannot find Brugge')
else:
print(f'Found a place at {results[0].centroid.x},{results[0].centroid.y}')
```
=== "NominatimAPI"
``` python
import nominatim_api as napi
with napi.NominatimAPI('/srv/nominatim-project') as api:
results = api.search('Brugge')
if not results:
print('Cannot find Brugge')
else:
print(f'Found a place at {results[0].centroid.x},{results[0].centroid.y}')
```
You may also configure Nominatim by setting environment variables. You may also configure Nominatim by setting environment variables.
Normally Nominatim will check the operating system environment. Lets Normally Nominatim will check the operating system environment. Lets
@ -148,9 +182,10 @@ like this:
``` ```
When the `environ` parameter is given, then only configuration variables When the `environ` parameter is given, then only configuration variables
from this dictionary will be used. from this dictionary will be used. The operating system's environment
variables will be ignored.
### Presenting results to humans ## Presenting results to humans
All search functions return full result objects from the database. Such a All search functions return full result objects from the database. Such a
result object contains lots of details: names, address information, OSM tags etc. result object contains lots of details: names, address information, OSM tags etc.

View File

@ -24,12 +24,11 @@ the placex table:
``` ```
import asyncio import asyncio
from pathlib import Path
import sqlalchemy as sa import sqlalchemy as sa
from nominatim_api import NominatimAPIAsync from nominatim_api import NominatimAPIAsync
async def print_table_size(): async def print_table_size():
api = NominatimAPIAsync(Path('.')) api = NominatimAPIAsync()
async with api.begin() as conn: async with api.begin() as conn:
cnt = await conn.scalar(sa.select(sa.func.count()).select_from(conn.t.placex)) cnt = await conn.scalar(sa.select(sa.func.count()).select_from(conn.t.placex))

View File

@ -4,6 +4,7 @@ theme:
name: material name: material
features: features:
- navigation.tabs - navigation.tabs
- toc.integrate
plugins: plugins:
- privacy - privacy
copyright: Copyright © Nominatim developer community copyright: Copyright © Nominatim developer community
@ -71,6 +72,7 @@ markdown_extensions:
alternate_style: true alternate_style: true
- def_list - def_list
- toc: - toc:
toc_depth: 4
permalink: 🔗 permalink: 🔗
extra_css: [extra.css, styles.css] extra_css: [extra.css, styles.css]
exclude_docs: | exclude_docs: |