From: Sarah Hoffmann Date: Wed, 30 Dec 2020 10:30:58 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/master' X-Git-Tag: deploy~188 X-Git-Url: https://git.openstreetmap.org/nominatim.git/commitdiff_plain/c3238682a8867edfb3c052ca4d2d27b3926ad17a?hp=0aa2ca64d2d7492b05f2e541764fbe159eb5a187 Merge remote-tracking branch 'upstream/master' --- diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 22a975e5..761a14d7 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -7,16 +7,16 @@ assignees: '' --- -Before opening a new feature request, please search through the open issue to check that your request hasn't been reported already. + **Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + **Describe the solution you'd like** -A clear and concise description of what you want to happen. + **Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. + **Additional context** -Add any other context or screenshots about the feature request here. + diff --git a/.github/ISSUE_TEMPLATE/report-issues-with-search-results.md b/.github/ISSUE_TEMPLATE/report-issues-with-search-results.md index 81e55ecd..2ec8ee8e 100644 --- a/.github/ISSUE_TEMPLATE/report-issues-with-search-results.md +++ b/.github/ISSUE_TEMPLATE/report-issues-with-search-results.md @@ -9,7 +9,7 @@ assignees: '' ## What did you search for? -Please try to provide a link to your search. You can go to https://nominatim.openstreetmap.org and repeat your search there. If you originally found the issue somewhere else, please tell us what software/website you were using. + ## What result did you get? @@ -17,11 +17,11 @@ Please try to provide a link to your search. You can go to https://nominatim.op **Is the result in the right place and just named wrongly?** -Please tell us the display name you expected. + **Is the result missing completely?** -Make sure that the data you are looking for is in OpenStreetMap. Provide a link to the OpenStreetMap object or if you cannot get it, a link to the map on https://openstreetmap.org where you expect the result to be. + ## Further details -Anything else we should know about the search. Particularities with addresses in the area etc. + diff --git a/.github/ISSUE_TEMPLATE/report-problems-with-the-software.md b/.github/ISSUE_TEMPLATE/report-problems-with-the-software.md index fef67cbc..c7e74280 100644 --- a/.github/ISSUE_TEMPLATE/report-problems-with-the-software.md +++ b/.github/ISSUE_TEMPLATE/report-problems-with-the-software.md @@ -7,13 +7,13 @@ assignees: '' --- -___Note: if you are installing Nominatim through a docker image, you should report issues with the installation process with the docker repository first.___ + **Describe the bug** -A clear and concise description of what the bug is. + **To Reproduce** -Please describe what you did to get to the issue. + **Software Environment (please complete the following information):** - Nominatim version: @@ -27,5 +27,10 @@ Please describe what you did to get to the issue. - type and size of disks: - bare metal/AWS/other cloud service: +**Postgresql Configuration:** + + + **Additional context** -Add any other context about the problem here. + + diff --git a/.github/actions/build-nominatim/action.yml b/.github/actions/build-nominatim/action.yml index 9bb66df3..555d7ee2 100644 --- a/.github/actions/build-nominatim/action.yml +++ b/.github/actions/build-nominatim/action.yml @@ -5,7 +5,8 @@ runs: steps: - name: Install prerequisits - run: sudo apt-get install -y -qq libboost-system-dev libboost-filesystem-dev libexpat1-dev zlib1g-dev libbz2-dev libpq-dev libproj-dev python3-psycopg2 python3-pyosmium + run: | + sudo apt-get install -y -qq libboost-system-dev libboost-filesystem-dev libexpat1-dev zlib1g-dev libbz2-dev libpq-dev libproj-dev python3-psycopg2 python3-pyosmium php-symfony-dotenv shell: bash - name: Configure diff --git a/.github/actions/setup-postgresql/action.yml b/.github/actions/setup-postgresql/action.yml index 98086f2d..0742e663 100644 --- a/.github/actions/setup-postgresql/action.yml +++ b/.github/actions/setup-postgresql/action.yml @@ -1,26 +1,45 @@ name: 'Setup Postgresql and Postgis' +inputs: + postgresql-version: + description: 'Version of PostgreSQL to install' + required: true + postgis-version: + description: 'Version of Postgis to install' + required: true + runs: using: "composite" steps: - - name: Install postgis + - name: Remove existing PostgreSQL + run: | + sudo apt-get update -qq + sudo apt-get purge -yq postgresql* + shell: bash + + - name: Install PostgreSQL run: | - sudo apt-get update -qq - sudo apt-get install -y -qq postgresql-13-postgis-3 postgresql-13-postgis-3-scripts postgresql-server-dev-13 + sudo apt-get install -y -qq --no-install-suggests --no-install-recommends postgresql-client-${PGVER} postgresql-${PGVER}-postgis-${POSTGISVER} postgresql-${PGVER}-postgis-${POSTGISVER}-scripts postgresql-contrib-${PGVER} postgresql-${PGVER} postgresql-server-dev-${PGVER} shell: bash + env: + PGVER: ${{ inputs.postgresql-version }} + POSTGISVER: ${{ inputs.postgis-version }} - name: Adapt postgresql configuration run: | - echo 'fsync = off' | sudo tee /etc/postgresql/13/main/conf.d/local.conf - echo 'synchronous_commit = off' | sudo tee -a /etc/postgresql/13/main/conf.d/local.conf - echo 'full_page_writes = off' | sudo tee -a /etc/postgresql/13/main/conf.d/local.conf - echo 'shared_buffers = 1GB' | sudo tee -a /etc/postgresql/13/main/conf.d/local.conf + echo 'fsync = off' | sudo tee /etc/postgresql/${PGVER}/main/conf.d/local.conf + echo 'synchronous_commit = off' | sudo tee -a /etc/postgresql/${PGVER}/main/conf.d/local.conf + echo 'full_page_writes = off' | sudo tee -a /etc/postgresql/${PGVER}/main/conf.d/local.conf + echo 'shared_buffers = 1GB' | sudo tee -a /etc/postgresql/${PGVER}/main/conf.d/local.conf + echo 'port = 5432' | sudo tee -a /etc/postgresql/${PGVER}/main/conf.d/local.conf shell: bash + env: + PGVER: ${{ inputs.postgresql-version }} - name: Setup database run: | - sudo systemctl start postgresql + sudo systemctl restart postgresql sudo -u postgres createuser -S www-data sudo -u postgres createuser -s runner shell: bash diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index f1da4616..cbb7aa6c 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -6,11 +6,26 @@ jobs: tests: runs-on: ubuntu-20.04 + strategy: + matrix: + postgresql: [9.5, 13] + include: + - postgresql: 9.5 + postgis: 2.5 + - postgresql: 13 + postgis: 3 + steps: - uses: actions/checkout@v2 with: submodules: true + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: phpunit, phpcs + - name: Get Date id: get-date run: | @@ -20,11 +35,14 @@ jobs: - uses: actions/cache@v2 with: path: | - data/country_osm_grid.sql.gz - monaco-latest.osm.pbf + {{ github.workspace }}/data/country_osm_grid.sql.gz + {{ github.workspace }}/monaco-latest.osm.pbf key: nominatim-data-${{ steps.get-date.outputs.date }} - uses: ./.github/actions/setup-postgresql + with: + postgresql-version: ${{ matrix.postgresql }} + postgis-version: ${{ matrix.postgis }} - uses: ./.github/actions/build-nominatim - name: Install test prerequsites @@ -60,17 +78,19 @@ jobs: - uses: actions/cache@v2 with: path: | - data/country_osm_grid.sql.gz - monaco-latest.osm.pbf + {{ github.workspace }}/data/country_osm_grid.sql.gz + {{ github.workspace }}/monaco-latest.osm.pbf key: nominatim-data-${{ steps.get-date.outputs.date }} - uses: ./.github/actions/setup-postgresql + with: + postgresql-version: 13 + postgis-version: 3 - uses: ./.github/actions/build-nominatim - name: Create configuration run: | - echo ' settings/local.php - echo " @define('CONST_Pyosmium_Binary', '/usr/lib/python3-pyosmium/pyosmium-get-changes');" >> settings/local.php + echo "NOMINATIM_PYOSMIUM_BINARY=/usr/lib/python3-pyosmium/pyosmium-get-changes" >> .env working-directory: build - name: Download import data diff --git a/CMakeLists.txt b/CMakeLists.txt index 816ce647..3fad37d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") project(nominatim) set(NOMINATIM_VERSION_MAJOR 3) -set(NOMINATIM_VERSION_MINOR 5) +set(NOMINATIM_VERSION_MINOR 6) set(NOMINATIM_VERSION_PATCH 0) set(NOMINATIM_VERSION "${NOMINATIM_VERSION_MAJOR}.${NOMINATIM_VERSION_MINOR}.${NOMINATIM_VERSION_PATCH}") @@ -96,38 +96,28 @@ endif() if (BUILD_IMPORTER) set(CUSTOMSCRIPTS - utils/check_import_finished.php - utils/country_languages.php - utils/importWikipedia.php - utils/export.php - utils/query.php - utils/setup.php - utils/specialphrases.php - utils/update.php - utils/warm.php + check_import_finished.php + country_languages.php + importWikipedia.php + export.php + query.php + setup.php + specialphrases.php + update.php + warm.php ) foreach (script_source ${CUSTOMSCRIPTS}) configure_file(${PROJECT_SOURCE_DIR}/cmake/script.tmpl - ${PROJECT_BINARY_DIR}/${script_source}) + ${PROJECT_BINARY_DIR}/utils/${script_source}) endforeach() endif() #----------------------------------------------------------------------------- -# webserver scripts (API only) +# Targets for running a development webserver from the build directory. #----------------------------------------------------------------------------- if (BUILD_API) - set(WEBSITESCRIPTS - website/deletable.php - website/details.php - website/lookup.php - website/polygons.php - website/reverse.php - website/search.php - website/status.php - ) - set(WEBSITEFILES 403.html 509.html @@ -138,24 +128,11 @@ if (BUILD_API) taginfo.json ) - foreach (script_source ${WEBSITESCRIPTS}) - configure_file(${PROJECT_SOURCE_DIR}/cmake/website.tmpl - ${PROJECT_BINARY_DIR}/${script_source}) - endforeach() - - set(WEBPATHS css images js) - foreach (webfile ${WEBSITEFILES}) configure_file(${PROJECT_SOURCE_DIR}/website/${webfile} ${PROJECT_BINARY_DIR}/website/${webfile}) endforeach() - foreach (wp ${WEBPATHS}) - execute_process( - COMMAND ln -sf ${PROJECT_SOURCE_DIR}/website/${wp} ${PROJECT_BINARY_DIR}/website/ - ) - endforeach() - add_custom_target(serve php -S 127.0.0.1:8088 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/website @@ -167,13 +144,6 @@ if (BUILD_API) ) endif() -#----------------------------------------------------------------------------- -# default settings -#----------------------------------------------------------------------------- - -configure_file(${PROJECT_SOURCE_DIR}/settings/defaults.php - ${PROJECT_BINARY_DIR}/settings/settings.php) - #----------------------------------------------------------------------------- # Tests #----------------------------------------------------------------------------- diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 89b76e3b..2d2877bf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,41 +7,6 @@ Please always open a separate issue for each problem. In particular, do not add your bugs to closed issues. They may looks similar to you but often are completely different from the maintainer's point of view. -### When Reporting Bad Search Results... - -Please make sure to add the following information: - - * the URL of the query that produces the bad result - * the result you are getting - * the expected result, preferably a link to the OSM object you want to find, - otherwise an address that is as precise as possible - -To get the link to the OSM object, you can try the following: - - * go to https://openstreetmap.org - * zoom to the area of the map where you expect the result and - zoom in as much as possible - * click on the question mark on the right side of the map, - then with the queston cursor on the map where your object is located - * find the object of interest in the list that appears on the left side - * click on the object and report the URL back that the browser shows - -### When Reporting Bugs... - -Please add the following information to your issue: - - * hardware configuration: RAM size, CPUs, kind and size of disks - * Operating system (also mention if you are running on a cloud service) - * Postgres and Postgis version - * list of settings you changed in your Postgres configuration - * Nominatim version (release version or, - if you run from the git repo, the output of `git rev-parse HEAD`) - * (if applicable) exact command line of the command that was causing the issue - -Bug reports that do not include extensive information about your system, -about the problem and about what you have been trying to debug the problem -will be closed. - ## Workflow for Pull Requests We love to get pull requests from you. We operate the "Fork & Pull" model diff --git a/ChangeLog b/ChangeLog index 42fde12a..633d0c53 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,50 @@ +3.6.0 + + * add full support for searching by and displaying of addr:* tags + * improve address output for large-area objects + * better use of country names from OSM data for search and display + * better debug output for reverse call + * add support for addr:place links without an place equivalent in OSM + * improve finding postcodes with normalisation artefacts + * batch object to index for rank 30, avoiding a wrap-around of transaction + IDs in PostgreSQL + * introduce dynamic address rank computation for administrative boundaries + depending on linked objects and their place in the admin level hierarchy + * add country-specific address ranking for Indonesia, Russia, Belgium and + the Netherlands (thanks @hendrikmoree) + * make sure wikidata/wikipedia tags are imported for all styles + * make POIs searchable by name and housenumber (thanks @joy-yyd) + * reverse geocoding now ignores places without an address rank (rivers etc.) + * installation of a webserver is no longer mandatory, for development + use the php internal webserver via 'make serve + * reduce the influence of place nodes in addresses + * drop support for the unspecific is_in tag + * various minor tweaks to supplied styles + * move HTML web frontend into its own project + * move scripts for processing external data sources into separate directories + * introduce separate configuration for website (thanks @krahulreddy) + * update documentation, in particular, clean up development docs + * update osm2pgsql to 1.4.0 + +3.5.2 + + * ensure that wikipedia tags are imported for all styles + * reinstate verbosity for indexing during updates + * make house number reappear in display name on named POIs + * introduce batch processing in indexer to avoid transaction ID overrun + * increase splitting for large geometries to improve indexing speed + * remove deprecated get_magic_quotes_gpc() function + * make sure that all postcodes have an entry in word and are thus searchable + * remove use of ST_Covers in conjunction woth ST_Intersects, + causes bad query planning and slow updates in Postgis3 + * update osm2pgsql + +3.5.1 + + * disable jit and parallel processing in PostgreSQL for osm2pgsql + * update libosmium to 2.15.6 (fixes an issue with processing hanging + on large multipolygons) + 3.5.0 * structured select on HTML search page @@ -11,7 +58,7 @@ * cleanup of partition function * improve parenting for large POIs * add support for Postgresql 12 and Postgis 3 - * add earlier cleanup when --drop is given, to reduce meory usage + * add earlier cleanup when --drop is given, to reduce memory usage * remove use of place_id in URLs * replace C nominatim indexer with a simpler Python implementation * split up the huge sql/functions.sql file diff --git a/cmake/script.tmpl b/cmake/script.tmpl index 8146ca8b..4d9224b0 100755 --- a/cmake/script.tmpl +++ b/cmake/script.tmpl @@ -1,4 +1,7 @@ #!@PHP_BIN@ -Cq '); +NOMINATIM_DATABASE_MODULE_PATH="" ``` -Now change the `CONST_Database_DSN` to point to your remote server and continue +Now change the `NOMINATIM_DATABASE_DSN` to point to your remote server and continue to follow the [standard instructions for importing](/admin/Import). diff --git a/docs/admin/Faq.md b/docs/admin/Faq.md index bca6b49d..6203959d 100644 --- a/docs/admin/Faq.md +++ b/docs/admin/Faq.md @@ -211,11 +211,3 @@ for more information. ### Can I import negative OSM ids into Nominatim? See [this question of Stackoverflow](https://help.openstreetmap.org/questions/64662/nominatim-flatnode-with-negative-id). - -### Missing XML or text declaration - -The website might show: `XML Parsing Error: XML or text declaration not at start of entity Location.` - -Make sure there are no spaces at the beginning of your `settings/local.php` file. - - diff --git a/docs/admin/Import.md b/docs/admin/Import.md index 334c1b75..41942d6f 100644 --- a/docs/admin/Import.md +++ b/docs/admin/Import.md @@ -5,18 +5,17 @@ from an OSM planet file and how to keep the database up to date. It is assumed that you have already successfully installed the Nominatim software itself, if not return to the [installation page](Installation.md). -## Configuration setup in settings/local.php +## Configuration setup in `.env` -The Nominatim server can be customized via the file `settings/local.php` -in the build directory. Note that this is a PHP file, so it must always -start like this: - - --all 2>&1 | tee setup.log ``` -***Note for full planet imports:*** Even on a perfectly configured machine -the import of a full planet takes at least 2 days. Once you see messages +### Notes on full planet imports + +Even on a perfectly configured machine +the import of a full planet takes around 2 days. Once you see messages with `Rank .. ETA` appear, the indexing process has started. This part takes the most time. There are 30 ranks to process. Rank 26 and 30 are the most complex. They take each about a third of the total import time. If you have not reached @@ -167,11 +170,12 @@ configuration as it may not be optimal for the import. ### Notes on memory usage -In the first step of the import Nominatim uses osm2pgsql to load the OSM data -into the PostgreSQL database. This step is very demanding in terms of RAM usage. -osm2pgsql and PostgreSQL are running in parallel at this point. PostgreSQL -blocks at least the part of RAM that has been configured with the -`shared_buffers` parameter during [PostgreSQL tuning](Installation#postgresql-tuning) +In the first step of the import Nominatim uses [osm2pgsql](https://osm2pgsql.org) +to load the OSM data into the PostgreSQL database. This step is very demanding +in terms of RAM usage. osm2pgsql and PostgreSQL are running in parallel at +this point. PostgreSQL blocks at least the part of RAM that has been configured +with the `shared_buffers` parameter during +[PostgreSQL tuning](Installation#postgresql-tuning) and needs some memory on top of that. osm2pgsql needs at least 2GB of RAM for its internal data structures, potentially more when it has to process very large relations. In addition it needs to maintain a cache for node locations. The size @@ -182,10 +186,10 @@ completely and leave the memory for the flatnode file. Nominatim will do this by default, so you do not need to configure anything in this case. For imports without a flatnode file, set `--osm2pgsql-cache` approximately to -the size of the OSM pbf file (in MB) you are importing. Make sure you leave -enough RAM for PostgreSQL and osm2pgsql as mentioned above. If the system starts -swapping or you are getting out-of-memory errors, reduce the cache size or -even consider using a flatnode file. +the size of the OSM pbf file you are importing. The size needs to be given in +MB. Make sure you leave enough RAM for PostgreSQL and osm2pgsql as mentioned +above. If the system starts swapping or you are getting out-of-memory errors, +reduce the cache size or even consider using a flatnode file. ### Verify the import @@ -197,7 +201,7 @@ Run this script to verify all required tables and indices got created successful ### Setting up the website -Run the following command to set up the configuration file for the website +Run the following command to set up the configuration file for the API frontend `settings/settings-frontend.php`. These settings are used in website/*.php files. ```sh @@ -264,9 +268,9 @@ entire US adds about 10GB to your database. ./utils/setup.php --import-tiger-data - 3. Enable use of the Tiger data in your `settings/local.php` by adding: + 3. Enable use of the Tiger data in your `.env` by adding: - @define('CONST_Use_US_Tiger_Data', true); + NOMINATIM_USE_US_TIGER_DATA=yes 4. Apply the new settings: diff --git a/docs/admin/Installation.md b/docs/admin/Installation.md index 8ca41e8f..4cd2ad0e 100644 --- a/docs/admin/Installation.md +++ b/docs/admin/Installation.md @@ -57,12 +57,12 @@ A minimum of 2GB of RAM is required or installation will fail. For a full planet import 64GB of RAM or more are strongly recommended. Do not report out of memory problems if you have less than 64GB RAM. -For a full planet install you will need at least 800GB of hard disk space -(take into account that the OSM database is growing fast). SSD disks -will help considerably to speed up import and queries. +For a full planet install you will need at least 900GB of hard disk space. +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 -at least 2 days. Without SSDs 7-8 days are more realistic. +around 2 days. On traditional spinning disks, 7-8 days are more realistic. ## Tuning the PostgreSQL database diff --git a/docs/admin/Migration.md b/docs/admin/Migration.md index 21bbb51a..3f330bb9 100644 --- a/docs/admin/Migration.md +++ b/docs/admin/Migration.md @@ -6,7 +6,7 @@ to newer versions of Nominatim. SQL statements should be executed from the PostgreSQL commandline. Execute `psql nominatim` to enter command line mode. -## 3.5.0 -> master +## 3.5.0 -> 3.6.0 ### Change of layout of search_name_* tables diff --git a/docs/admin/Setup-Nominatim-UI.md b/docs/admin/Setup-Nominatim-UI.md index 9a6e163b..6aee4a0b 100644 --- a/docs/admin/Setup-Nominatim-UI.md +++ b/docs/admin/Setup-Nominatim-UI.md @@ -17,7 +17,12 @@ Clone the source from github: git clone https://github.com/osm-search/nominatim-ui -Adapt the configuration `dist/config.js` to your needs. You need at least +Copy the example configuration into the right place: + + cd nominatim-ui + cp dist/config.example.js dist/config.js + +Now adapt the configuration to your needs. You need at least to change the `Nominatim_API_Endpoint` to point to your Nominatim installation. Then you can just test it locally by spinning up a webserver in the `dist` @@ -66,7 +71,7 @@ map $args $format { ~(^|&)format= other; } -# Determine from the URI and the format parameter aboce if forwarding is needed. +# Determine from the URI and the format parameter above if forwarding is needed. map $uri/$format $forward_to_ui { default 1; # The default is to forward. ~^/ui 0; # If the URI point to the UI already, we are done. diff --git a/docs/admin/Update.md b/docs/admin/Update.md index b4692321..98f5244a 100644 --- a/docs/admin/Update.md +++ b/docs/admin/Update.md @@ -4,9 +4,9 @@ There are many different ways to update your Nominatim database. The following section describes how to keep it up-to-date with Pyosmium. For a list of other methods see the output of `./utils/update.php --help`. -!!! warning +!!! important If you have configured a flatnode file for the import, then you - need to keep this flatnode file around for updates as well. + need to keep this flatnode file around for updates. #### Installing the newest version of Pyosmium @@ -19,9 +19,9 @@ pip3 install --user osmium Nominatim needs a tool called `pyosmium-get-changes` which comes with Pyosmium. You need to tell Nominatim where to find it. Add the -following line to your `settings/local.php`: +following line to your `.env`: - @define('CONST_Pyosmium_Binary', '/home/user/.local/bin/pyosmium-get-changes'); + NOMINATIM_PYOSMIUM_BINARY=/home/user/.local/bin/pyosmium-get-changes The path above is fine if you used the `--user` parameter with pip. Replace `user` with your user name. @@ -32,15 +32,15 @@ Next the update needs to be initialised. By default Nominatim is configured to update using the global minutely diffs. If you want a different update source you will need to add some settings -to `settings/local.php`. For example, to use the daily country extracts +to `.env`. For example, to use the daily country extracts diffs for Ireland from Geofabrik add the following: - // base URL of the replication service - @define('CONST_Replication_Url', 'https://download.geofabrik.de/europe/ireland-and-northern-ireland-updates'); - // How often upstream publishes diffs - @define('CONST_Replication_Update_Interval', '86400'); - // How long to sleep if no update found yet - @define('CONST_Replication_Recheck_Interval', '900'); + # base URL of the replication service + NOMINATIM_REPLICATION_URL="https://download.geofabrik.de/europe/ireland-and-northern-ireland-updates" + # How often upstream publishes diffs + NOMINATIM_REPLICATION_UPDATE_INTERVAL=86400 + # How long to sleep if no update found yet + NOMINATIM_REPLICATION_RECHECK_INTERVAL=900 To set up the update process now run the following command: diff --git a/docs/api/Details.md b/docs/api/Details.md index 2776bfe2..08802f9a 100644 --- a/docs/api/Details.md +++ b/docs/api/Details.md @@ -1,19 +1,22 @@ # Place details -Lookup details about a single place by id. The default output is HTML for debugging search logic and results. +Show all details about a single place saved in the database. -**The details page (including JSON output) exists for debugging only and must not be downloaded automatically**, see [Nominatim Usage Policy](https://operations.osmfoundation.org/policies/nominatim/). +!!! warning + The details page exists for debugging only. You may not use it in scripts + or to automatically query details about a result. + See [Nominatim Usage Policy](https://operations.osmfoundation.org/policies/nominatim/). ## Parameters The details API supports the following two request formats: -``` - https://nominatim.openstreetmap.org/details?osmtype=[N|W|R]&osmid=&class= +``` xml +https://nominatim.openstreetmap.org/details?osmtype=[N|W|R]&osmid=&class= ``` -`osmtype` and `osmid` are required parameter. The type is one of node (N), way (W) +`osmtype` and `osmid` are required parameters. The type is one of node (N), way (W) or relation (R). The id must be a number. The `class` parameter is optional and allows to distinguish between entries, when the corresponding OSM object has more than one main tag. For example, when a place is tagged with `tourism=hotel` and @@ -23,36 +26,34 @@ to get exactly the one you want. If there are multiple places in the database but the `class` parameter is left out, then one of the places will be chosen at random and displayed. -``` - https://nominatim.openstreetmap.org/details?place_id= +``` xml +https://nominatim.openstreetmap.org/details?place_id= ``` -Placeids are assigned sequentially during Nominatim data import. The id for a place is different between Nominatim installation (servers) and changes when data gets reimported. Therefore it can't be used as permanent id and shouldn't be used in bug reports. +Place IDs are assigned sequentially during Nominatim data import. The ID +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. Additional optional parameters are explained below. ### Output format -* `format=[html|json]` - -See [Place Output Formats](Output.md) for details on each format. (Default: html) - * `json_callback=` Wrap JSON output in a callback function (JSONP) i.e. `()`. -Only has an effect for JSON output formats. * `pretty=[0|1]` -For JSON output will add indentation to make it more human-readable. (Default: 0) +Add indentation to make it more human-readable. (Default: 0) ### Output details * `addressdetails=[0|1]` -Include a breakdown of the address into elements. (Default for JSON: 0, for HTML: 1) +Include a breakdown of the address into elements. (Default: 0) * `keywords=[0|1]` @@ -60,11 +61,16 @@ Include a list of name keywords and address keywords (word ids). (Default: 0) * `linkedplaces=[0|1]` -Include details of places higher in the address hierarchy. E.g. for a street this is usually the city, state, postal code, country. (Default: 1) +Include a 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]` -Include details of places lower in the address hierarchy. E.g. for a city this usually a list of streets, suburbs, rivers. (Default for JSON: 0, for HTML: 1) +Include details of places lower in the address hierarchy. (Default: 0) * `group_hierarchy=[0|1]` @@ -72,7 +78,7 @@ For JSON output will group the places by type. (Default: 0) * `polygon_geojson=[0|1]` -Include geometry of result. (Default for JSON: 0, for HTML: 1) +Include geometry of result. (Default: 0) ### Language of results @@ -86,10 +92,6 @@ comma-separated list of language codes. ## Examples -##### HTML - -[https://nominatim.openstreetmap.org/details.php?osmtype=W&osmid=38210407](https://nominatim.openstreetmap.org/details.php?osmtype=W&osmid=38210407) - ##### JSON [https://nominatim.openstreetmap.org/details.php?osmtype=W&osmid=38210407&format=json](https://nominatim.openstreetmap.org/details.php?osmtype=W&osmid=38210407&format=json) diff --git a/docs/api/Lookup.md b/docs/api/Lookup.md index 2412be1e..93729262 100644 --- a/docs/api/Lookup.md +++ b/docs/api/Lookup.md @@ -56,6 +56,21 @@ specified in the "Accept-Language" HTTP header. Either use a standard RFC2616 accept-language string or a simple comma-separated list of language codes. +### Polygon output + +* `polygon_geojson=1` +* `polygon_kml=1` +* `polygon_svg=1` +* `polygon_text=1` + +Output geometry of results as a GeoJSON, KML, SVG or WKT. Only one of these +options can be used at a time. (Default: 0) + +* `polygon_threshold=0.0` + +Return a simplified version of the output geometry. The parameter is the +tolerance in degrees with which the geometry may differ from the original +geometry. Topology is preserved in the result. (Default: 0.0) ### Other diff --git a/docs/api/Output.md b/docs/api/Output.md index c8589f64..a37cbe0b 100644 --- a/docs/api/Output.md +++ b/docs/api/Output.md @@ -2,12 +2,10 @@ The [/reverse](Reverse.md), [/search](Search.md) and [/lookup](Lookup.md) API calls produce very similar output which is explained in this section. -There is one section for each format which is selectable via the `format` -parameter. +There is one section for each format. The format correspond to what was +selected via the `format` parameter. -## Formats - -### JSON +## JSON The JSON format returns an array of places (for search and lookup) or a single place (for reverse) of the following format: @@ -41,13 +39,13 @@ a single place (for reverse) of the following format: "wikipedia": "en:London", "population": "8416535" } - }, + } ``` The possible fields are: * `place_id` - reference to the Nominatim internal database ID ([see notes](#place_id-is-not-a-persistent-id)) - * `osm_type`, `osm_id` - reference to the OSM object + * `osm_type`, `osm_id` - reference to the OSM object ([see notes](#osm-reference)) * `boundingbox` - area of corner coordinates ([see notes](#boundingbox)) * `lat`, `lon` - latitude and longitude of the centroid of the object * `display_name` - full comma-separated address @@ -62,22 +60,22 @@ The possible fields are: * `geojson`, `svg`, `geotext`, `geokml` - full geometry (only with the appropriate `polygon_*` parameter) -### JSONv2 +## JSONv2 This is the same as the JSON format with two changes: * `class` renamed to `category` * additional field `place_rank` with the search rank of the object -### GeoJSON +## GeoJSON This format follows the [RFC7946](https://geojson.org). Every feature includes a bounding box (`bbox`). -The feature list has the following fields: +The properties object has the following fields: * `place_id` - reference to the Nominatim internal database ID ([see notes](#place_id-is-not-a-persistent-id)) - * `osm_type`, `osm_id` - reference to the OSM object + * `osm_type`, `osm_id` - reference to the OSM object ([see notes](#osm-reference)) * `category`, `type` - key and value of the main OSM tag * `display_name` - full comma-separated address * `place_rank` - class search rank @@ -92,13 +90,13 @@ The feature list has the following fields: Use `polygon_geojson` to output the full geometry of the object instead of the centroid. -### GeocodeJSON +## GeocodeJSON The GeocodeJSON format follows the [GeocodeJSON spec 0.1.0](https://github.com/geocoders/geocodejson-spec). The following feature attributes are implemented: - * `osm_type`, `osm_id` - reference to the OSM object (unofficial extension) + * `osm_type`, `osm_id` - reference to the OSM object (unofficial extension, [see notes](#osm-reference)) * `type` - value of the main tag of the object (e.g. residential, restaurant, ...) * `label` - full comma-separated address * `name` - localised name of the place @@ -110,18 +108,18 @@ The following feature attributes are implemented: Use `polygon_geojson` to output the full geometry of the object instead of the centroid. -### XML +## XML The XML response returns one or more place objects in slightly different formats depending on the API call. -#### Reverse +### Reverse ``` - Bavaria, Germany @@ -148,7 +146,7 @@ attribution to OSM and the original querystring. The place information can be found in the `result` element. The attributes of that element contain: * `place_id` - reference to the Nominatim internal database ID ([see notes](#place_id-is-not-a-persistent-id)) - * `osm_type`, `osm_id` - reference to the OSM object + * `osm_type`, `osm_id` - reference to the OSM object ([see notes](#osm-reference)) * `ref` - content of `ref` tag if it exists * `lat`, `lon` - latitude and longitude of the centroid of the object * `boundingbox` - comma-separated list of corner coordinates ([see notes](#boundingbox)) @@ -159,14 +157,14 @@ The full address of the result can be found in the content of the Additional information requested with `addressdetails=1`, `extratags=1` and `namedetails=1` can be found in extra elements. -#### Search and Lookup +### Search and Lookup ``` - +https://nominatim.openstreetmap.org/reverse?lat=&lon=& ``` -There are two ways how the requested location can be specified: - -* `lat=` `lon=` - - A geographic location to generate an address for. The coordiantes must be - in WGS84 format. - -* `osm_type=[N|W|R]` `osm_id=` +where `lat` and `lon` are latitude and longitutde of a coordinate in WGS84 +projection. The API returns exactly one result or an error when the coordinate +is in an area with no OSM data coverage. - A specific OSM node(N), way(W) or relation(R) to return an address for. +Additional paramters are accepted as listed below. -In both cases exactly one object is returned. The two input parameters cannot -be used at the same time. Both accept the additional optional parameters listed -below. +!!! warning "Deprecation warning" + The reverse API used to allow address lookup for a single OSM object by + its OSM id. This use is now deprecated. Use the [Address Lookup API](../Lookup) + instead. ### Output format * `format=[xml|json|jsonv2|geojson|geocodejson]` -See [Place Output Formats](Output.md) for details on each format. (Default: html) +See [Place Output Formats](Output.md) for details on each format. (Default: xml) * `json_callback=` @@ -69,8 +81,9 @@ comma-separated list of language codes. * `zoom=[0-18]` -Level of detail required for the address. Default: 18. This is a number that corresponds -roughly to the zoom level used in map frameworks like Leaflet.js, Openlayers etc. +Level of detail required for the address. Default: 18. This is a number that +corresponds roughly to the zoom level used in XYZ tile sources in frameworks +like Leaflet.js, Openlayers etc. In terms of address details the zoom levels are as follows: zoom | address detail @@ -97,7 +110,7 @@ options can be used at a time. (Default: 0) * `polygon_threshold=0.0` -Simplify the output geometry before returning. The parameter is the +Return a simplified version of the output geometry. The parameter is the tolerance in degrees with which the geometry may differ from the original geometry. Topology is preserved in the result. (Default: 0.0) diff --git a/docs/api/Search.md b/docs/api/Search.md index 9f73594d..eada817f 100644 --- a/docs/api/Search.md +++ b/docs/api/Search.md @@ -1,30 +1,27 @@ # Search queries -The search API allows you to look up a location from a textual description. -Nominatim supports structured as well as free-form search queries. +The search API allows you to look up a location from a textual description +or address. Nominatim supports structured and free-form search queries. The search query may also contain [special phrases](https://wiki.openstreetmap.org/wiki/Nominatim/Special_Phrases) which are translated into specific OpenStreetMap (OSM) tags (e.g. Pub => `amenity=pub`). -Note that this only limits the items to be found, it's not suited to return complete -lists of OSM objects of a specific type. For those use [Overpass API](https://overpass-api.de/). +This can be used to narrow down the kind of objects to be returned. -## Parameters - -The search API has the following two formats: +!!! warning + Special phrases are not suitable to query all objects of a certain type in an + area. Nominatim will always just return a collection of the best matches. To + download OSM data by object type, use the [Overpass API](https://overpass-api.de/). -``` - https://nominatim.openstreetmap.org/search/? -``` +## Parameters -This format only accepts a free-form query string where the -parts of the query are separated by slashes. +The search API has the following format: ``` https://nominatim.openstreetmap.org/search? ``` -In this form, the query may be given through two different sets of parameters: +The search term may be specified with two different sets of parameters: * `q=` @@ -46,13 +43,13 @@ In this form, the query may be given through two different sets of parameters: Structured requests are faster but are less robust against alternative OSM tagging schemas. **Do not combine with** `q=` **parameter**. -All three query forms accept the additional parameters listed below. +Both query forms accept the additional parameters listed below. ### Output format -* `format=[html|xml|json|jsonv2|geojson|geocodejson]` +* `format=[xml|json|jsonv2|geojson|geocodejson]` -See [Place Output Formats](Output.md) for details on each format. (Default: html) +See [Place Output Formats](Output.md) for details on each format. (Default: jsonv2) * `json_callback=` @@ -96,16 +93,16 @@ Limit search results to one or more countries. `` must be the e.g. `gb` for the United Kingdom, `de` for Germany. Each place in Nominatim is assigned to one country code based -on `admin_level=2` tags, in rare cases to none (for example in -international waters outside any country). +on OSM country boundaries. In rare cases a place may not be in any country +at all, for example, in international waters. * `exclude_place_ids=` @@ -122,10 +119,11 @@ are accepted as long as they span a real box. `x` is longitude, * `bounded=[0|1]` -When a viewbox is given, restrict the result to items contained with that +When a viewbox is given, restrict the result to items contained within that viewbox (see above). When `viewbox` and `bounded=1` are given, an amenity -only search is allowed. In this case, give the special keyword for the -amenity in square brackets, e.g. `[pub]`. (Default: 0) +only search is allowed. Give the special keyword for the amenity in square +brackets, e.g. `[pub]` and a selection of objects of this type is returned. +There is no guarantee that the result is complete. (Default: 0) ### Polygon output @@ -140,7 +138,7 @@ options can be used at a time. (Default: 0) * `polygon_threshold=0.0` -Simplify the output geometry before returning. The parameter is the +Return a simplified version of the output geometry. The parameter is the tolerance in degrees with which the geometry may differ from the original geometry. Topology is preserved in the result. (Default: 0.0) @@ -154,13 +152,11 @@ address to identify your requests. See Nominatim's [Usage Policy](https://operat * `dedupe=[0|1]` Sometimes you have several objects in OSM identifying the same place or -object in reality. The simplest case is a street being split in many +object in reality. The simplest case is a street being split into many different OSM ways due to different characteristics. Nominatim will attempt to detect such duplicates and only return one match unless this parameter is set to 0. (Default: 1) - - * `debug=[0|1]` Output assorted developer debug information. Data on internals of Nominatim's diff --git a/docs/develop/Development-Environment.md b/docs/develop/Development-Environment.md index b7b0a673..f0c36ba3 100644 --- a/docs/develop/Development-Environment.md +++ b/docs/develop/Development-Environment.md @@ -25,7 +25,7 @@ following packages should get you started: ## Prerequisites for testing and documentation -The Nominatim tests suite consists of behavioural tests (using behave) and +The Nominatim test suite consists of behavioural tests (using behave) and unit tests (using PHPUnit). It has the following additional requirements: * [behave test framework](https://behave.readthedocs.io) >= 1.2.5 @@ -85,7 +85,7 @@ All tests are located in the `\test` directory. Some of the behavioural test expect a test database to be present. You need at least 2GB RAM and 10GB disk space to create the database. -First create a separate directory for the test DB and Fetch the test planet +First create a separate directory for the test DB and fetch the test planet data and the Tiger data for South Dakota: ``` @@ -102,13 +102,20 @@ cmake $USERNAME/Nominatim make ``` -Copy the test settings: +Create a minimal test settings file: ``` -cp $USERNAME/Nominatim/test/testdb/local.php settings/ +tee .env << EOF +NOMINATIM_DATABASE_DSN="pgsql:dbname=test_api_nominatim" +NOMINATIM_USE_US_TIGER_DATA=yes +NOMINATIM_TIGER_DATA_PATH=tiger +NOMINATIM_WIKIPEDIA_DATA_PATH=$USERNAME/Nominatim/test/testdb +EOF ``` Inspect the file to check that all settings are correct for your local setup. +In particular, the wikipedia path should point to the test directory in your +Nominatim source directory. Now you can import the test database: diff --git a/docs/develop/Import.md b/docs/develop/Import.md index 5a323d26..c9612bb3 100644 --- a/docs/develop/Import.md +++ b/docs/develop/Import.md @@ -1,8 +1,8 @@ # OSM Data Import -OSM data is initially imported using osm2pgsql. Nominatim uses its own data -output style 'gazetteer', which differs from the output style created for -map rendering. +OSM data is initially imported using [osm2pgsql](https://osm2pgsql.org). +Nominatim uses its own data output style 'gazetteer', which differs from the +output style created for map rendering. ## Database Layout @@ -29,7 +29,7 @@ once with `class` of `highway` and once with a `class` of `bridge`. Thus the ## Configuring the Import How tags are interpreted and assigned to the different `place` columns can be -configured via the import style configuration file (`CONST_Import_style`). This +configured via the import style configuration file (`NOMINATIM_IMPORT_STYLE`). This is a JSON file which contains a list of rules which are matched against every tag of every object and then assign the tag its specific role. diff --git a/docs/develop/Ranking.md b/docs/develop/Ranking.md index 06f25500..5b1ca191 100644 --- a/docs/develop/Ranking.md +++ b/docs/develop/Ranking.md @@ -7,7 +7,7 @@ different purposes, which are explained in this chapter. ## Search rank The search rank describes the extent and importance of a place. It is used -when ranking search result. Simply put, if there are two results for a +when ranking search results. Simply put, if there are two results for a search query which are otherwise equal, then the result with the _lower_ search rank will be appear higher in the result list. @@ -87,9 +87,9 @@ into the database. There are a few hard-coded rules for the assignment: * highway nodes * landuse that is not an area -Other than that, the ranks can be freely assigned via the JSON file -defined with `CONST_Address_Level_Config` according to their type and -the country they are in. +Other than that, the ranks can be freely assigned via the JSON file according +to their type and the country they are in. The name of the config file to be +used can be changed with the setting `NOMINATIM_ADDRESS_LEVEL_CONFIG`. The address level configuration must consist of an array of configuration entries, each containing a tag definition and an optional country array: diff --git a/docs/develop/Testing.md b/docs/develop/Testing.md index 03f9574f..3c9d437f 100644 --- a/docs/develop/Testing.md +++ b/docs/develop/Testing.md @@ -27,7 +27,7 @@ This test directory is sturctured as follows: ## PHP Unit Tests (`test/php`) -Unit tests can be found in the php/ directory and tests selected php functions. +Unit tests can be found in the php/ directory. They test selected php functions. Very low coverage. To execute the test suite run @@ -89,7 +89,7 @@ feature of behave which comes in handy when writing new tests. ### API Tests (`test/bdd/api`) These tests are meant to test the different API endpoints and their parameters. -They require a to import several datasets into a test database. +They require to import several datasets into a test database. See the [Development Setup chapter](Development-Environment.md#preparing-the-test-database) for instructions on how to set up this database. @@ -128,7 +128,7 @@ the [phpcov](https://github.com/sebastianbergmann/phpcov) tool: These tests check the import and update of the Nominatim database. They do not test the correctness of osm2pgsql. Each test will write some data into the `place` -table (and optionally `the planet_osm_*` tables if required) and then run +table (and optionally the `planet_osm_*` tables if required) and then run Nominatim's processing functions on that. These tests need to create their own test databases. By default they will be @@ -139,4 +139,4 @@ needs superuser rights for postgres. ### Import Tests (`test/bdd/osm2pgsql`) These tests check that data is imported correctly into the place table. They -use the same template database as the Indexing tests, so the same remarks apply. +use the same template database as the DB Creation tests, so the same remarks apply. diff --git a/docs/develop/overview.md b/docs/develop/overview.md index c0a37a41..b5625a88 100644 --- a/docs/develop/overview.md +++ b/docs/develop/overview.md @@ -9,14 +9,14 @@ the address computation and the search frontend. The __data import__ stage reads the raw OSM data and extracts all information that is useful for geocoding. This part is done by osm2pgsql, the same tool that can also be used to import a rendering database. It uses the special -gazetteer output plugin in `osm2pgsql/output-gazetter.[ch]pp`. The result of +gazetteer output plugin in `osm2pgsql/src/output-gazetter.[ch]pp`. The result of the import can be found in the database table `place`. The __address computation__ or __indexing__ stage takes the data from `place` and adds additional information needed for geocoding. It ranks the places by importance, links objects that belong together and computes addresses and the search index. Most of this work is done in PL/pgSQL via database triggers -and can be found in the file `sql/functions.sql`. +and can be found in the files in the `sql/functions/` directory. The __search frontend__ implements the actual API. It takes search and reverse geocoding queries from the user, looks up the data and diff --git a/lib/AddressDetails.php b/lib/AddressDetails.php index a27d3e79..3d17ede5 100644 --- a/lib/AddressDetails.php +++ b/lib/AddressDetails.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/ClassTypes.php'); +require_once(CONST_LibDir.'/ClassTypes.php'); /** * Detailed list of address parts for a single result diff --git a/lib/DB.php b/lib/DB.php index 38b3e27e..0454a0ff 100644 --- a/lib/DB.php +++ b/lib/DB.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/DatabaseError.php'); +require_once(CONST_LibDir.'/DatabaseError.php'); /** * Uses PDO to access the database specified in the CONST_Database_DSN @@ -12,9 +12,9 @@ class DB { protected $connection; - public function __construct($sDSN = CONST_Database_DSN) + public function __construct($sDSN = null) { - $this->sDSN = $sDSN; + $this->sDSN = $sDSN ?? getSetting('DATABASE_DSN'); } public function connect($bNew = false, $bPersistent = true) diff --git a/lib/Geocode.php b/lib/Geocode.php index 6589f754..12f9da37 100644 --- a/lib/Geocode.php +++ b/lib/Geocode.php @@ -2,12 +2,12 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/PlaceLookup.php'); -require_once(CONST_BasePath.'/lib/Phrase.php'); -require_once(CONST_BasePath.'/lib/ReverseGeocode.php'); -require_once(CONST_BasePath.'/lib/SearchDescription.php'); -require_once(CONST_BasePath.'/lib/SearchContext.php'); -require_once(CONST_BasePath.'/lib/TokenList.php'); +require_once(CONST_LibDir.'/PlaceLookup.php'); +require_once(CONST_LibDir.'/Phrase.php'); +require_once(CONST_LibDir.'/ReverseGeocode.php'); +require_once(CONST_LibDir.'/SearchDescription.php'); +require_once(CONST_LibDir.'/SearchContext.php'); +require_once(CONST_LibDir.'/TokenList.php'); class Geocode { diff --git a/lib/PlaceLookup.php b/lib/PlaceLookup.php index a2f39ea3..6d7b6be1 100644 --- a/lib/PlaceLookup.php +++ b/lib/PlaceLookup.php @@ -2,8 +2,8 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/AddressDetails.php'); -require_once(CONST_BasePath.'/lib/Result.php'); +require_once(CONST_LibDir.'/AddressDetails.php'); +require_once(CONST_LibDir.'/Result.php'); class PlaceLookup { @@ -486,65 +486,63 @@ class PlaceLookup $aOutlineResult = array(); if (!$iPlaceID) return $aOutlineResult; - if (CONST_Search_AreaPolygons) { - // Get the bounding box and outline polygon - $sSQL = 'select place_id,0 as numfeatures,st_area(geometry) as area,'; - if ($fLonReverse != null && $fLatReverse != null) { - $sSQL .= ' ST_Y(closest_point) as centrelat,'; - $sSQL .= ' ST_X(closest_point) as centrelon,'; - } else { - $sSQL .= ' ST_Y(centroid) as centrelat, ST_X(centroid) as centrelon,'; - } - $sSQL .= ' ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,'; - $sSQL .= ' ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon'; - if ($this->bIncludePolygonAsGeoJSON) $sSQL .= ',ST_AsGeoJSON(geometry) as asgeojson'; - if ($this->bIncludePolygonAsKML) $sSQL .= ',ST_AsKML(geometry) as askml'; - if ($this->bIncludePolygonAsSVG) $sSQL .= ',ST_AsSVG(geometry) as assvg'; - if ($this->bIncludePolygonAsText) $sSQL .= ',ST_AsText(geometry) as astext'; - if ($fLonReverse != null && $fLatReverse != null) { - $sFrom = ' from (SELECT * , CASE WHEN (class = \'highway\') AND (ST_GeometryType(geometry) = \'ST_LineString\') THEN '; - $sFrom .=' ST_ClosestPoint(geometry, ST_SetSRID(ST_Point('.$fLatReverse.','.$fLonReverse.'),4326))'; - $sFrom .=' ELSE centroid END AS closest_point'; - $sFrom .= ' from placex where place_id = '.$iPlaceID.') as plx'; - } else { - $sFrom = ' from placex where place_id = '.$iPlaceID; - } - if ($this->fPolygonSimplificationThreshold > 0) { - $sSQL .= ' from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,'.$this->fPolygonSimplificationThreshold.') as geometry'.$sFrom.') as plx'; - } else { - $sSQL .= $sFrom; - } - - $aPointPolygon = $this->oDB->getRow($sSQL, null, 'Could not get outline'); + // Get the bounding box and outline polygon + $sSQL = 'select place_id,0 as numfeatures,st_area(geometry) as area,'; + if ($fLonReverse != null && $fLatReverse != null) { + $sSQL .= ' ST_Y(closest_point) as centrelat,'; + $sSQL .= ' ST_X(closest_point) as centrelon,'; + } else { + $sSQL .= ' ST_Y(centroid) as centrelat, ST_X(centroid) as centrelon,'; + } + $sSQL .= ' ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,'; + $sSQL .= ' ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon'; + if ($this->bIncludePolygonAsGeoJSON) $sSQL .= ',ST_AsGeoJSON(geometry) as asgeojson'; + if ($this->bIncludePolygonAsKML) $sSQL .= ',ST_AsKML(geometry) as askml'; + if ($this->bIncludePolygonAsSVG) $sSQL .= ',ST_AsSVG(geometry) as assvg'; + if ($this->bIncludePolygonAsText) $sSQL .= ',ST_AsText(geometry) as astext'; + if ($fLonReverse != null && $fLatReverse != null) { + $sFrom = ' from (SELECT * , CASE WHEN (class = \'highway\') AND (ST_GeometryType(geometry) = \'ST_LineString\') THEN '; + $sFrom .=' ST_ClosestPoint(geometry, ST_SetSRID(ST_Point('.$fLatReverse.','.$fLonReverse.'),4326))'; + $sFrom .=' ELSE centroid END AS closest_point'; + $sFrom .= ' from placex where place_id = '.$iPlaceID.') as plx'; + } else { + $sFrom = ' from placex where place_id = '.$iPlaceID; + } + if ($this->fPolygonSimplificationThreshold > 0) { + $sSQL .= ' from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,'.$this->fPolygonSimplificationThreshold.') as geometry'.$sFrom.') as plx'; + } else { + $sSQL .= $sFrom; + } - if ($aPointPolygon && $aPointPolygon['place_id']) { - if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null) { - $aOutlineResult['lat'] = $aPointPolygon['centrelat']; - $aOutlineResult['lon'] = $aPointPolygon['centrelon']; - } + $aPointPolygon = $this->oDB->getRow($sSQL, null, 'Could not get outline'); - if ($this->bIncludePolygonAsGeoJSON) $aOutlineResult['asgeojson'] = $aPointPolygon['asgeojson']; - if ($this->bIncludePolygonAsKML) $aOutlineResult['askml'] = $aPointPolygon['askml']; - if ($this->bIncludePolygonAsSVG) $aOutlineResult['assvg'] = $aPointPolygon['assvg']; - if ($this->bIncludePolygonAsText) $aOutlineResult['astext'] = $aPointPolygon['astext']; + if ($aPointPolygon && $aPointPolygon['place_id']) { + if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null) { + $aOutlineResult['lat'] = $aPointPolygon['centrelat']; + $aOutlineResult['lon'] = $aPointPolygon['centrelon']; + } - if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001) { - $aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius; - $aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius; - } + if ($this->bIncludePolygonAsGeoJSON) $aOutlineResult['asgeojson'] = $aPointPolygon['asgeojson']; + if ($this->bIncludePolygonAsKML) $aOutlineResult['askml'] = $aPointPolygon['askml']; + if ($this->bIncludePolygonAsSVG) $aOutlineResult['assvg'] = $aPointPolygon['assvg']; + if ($this->bIncludePolygonAsText) $aOutlineResult['astext'] = $aPointPolygon['astext']; - if (abs($aPointPolygon['minlon'] - $aPointPolygon['maxlon']) < 0.0000001) { - $aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius; - $aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius; - } + if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001) { + $aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius; + $aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius; + } - $aOutlineResult['aBoundingBox'] = array( - (string)$aPointPolygon['minlat'], - (string)$aPointPolygon['maxlat'], - (string)$aPointPolygon['minlon'], - (string)$aPointPolygon['maxlon'] - ); + if (abs($aPointPolygon['minlon'] - $aPointPolygon['maxlon']) < 0.0000001) { + $aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius; + $aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius; } + + $aOutlineResult['aBoundingBox'] = array( + (string)$aPointPolygon['minlat'], + (string)$aPointPolygon['maxlat'], + (string)$aPointPolygon['minlon'], + (string)$aPointPolygon['maxlon'] + ); } // as a fallback we generate a bounding box without knowing the size of the geometry diff --git a/lib/ReverseGeocode.php b/lib/ReverseGeocode.php index 032f442e..b420e5dd 100644 --- a/lib/ReverseGeocode.php +++ b/lib/ReverseGeocode.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/Result.php'); +require_once(CONST_LibDir.'/Result.php'); class ReverseGeocode { diff --git a/lib/SearchContext.php b/lib/SearchContext.php index c2898d27..8316a012 100644 --- a/lib/SearchContext.php +++ b/lib/SearchContext.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/lib.php'); +require_once(CONST_LibDir.'/lib.php'); /** diff --git a/lib/SearchDescription.php b/lib/SearchDescription.php index 15c6bf23..f0106063 100644 --- a/lib/SearchDescription.php +++ b/lib/SearchDescription.php @@ -2,9 +2,9 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/SpecialSearchOperator.php'); -require_once(CONST_BasePath.'/lib/SearchContext.php'); -require_once(CONST_BasePath.'/lib/Result.php'); +require_once(CONST_LibDir.'/SpecialSearchOperator.php'); +require_once(CONST_LibDir.'/SearchContext.php'); +require_once(CONST_LibDir.'/Result.php'); /** * Description of a single interpretation of a search query. diff --git a/lib/TokenList.php b/lib/TokenList.php index 1b6a1dcf..a419da6a 100644 --- a/lib/TokenList.php +++ b/lib/TokenList.php @@ -2,12 +2,12 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/TokenCountry.php'); -require_once(CONST_BasePath.'/lib/TokenHousenumber.php'); -require_once(CONST_BasePath.'/lib/TokenPostcode.php'); -require_once(CONST_BasePath.'/lib/TokenSpecialTerm.php'); -require_once(CONST_BasePath.'/lib/TokenWord.php'); -require_once(CONST_BasePath.'/lib/SpecialSearchOperator.php'); +require_once(CONST_LibDir.'/TokenCountry.php'); +require_once(CONST_LibDir.'/TokenHousenumber.php'); +require_once(CONST_LibDir.'/TokenPostcode.php'); +require_once(CONST_LibDir.'/TokenSpecialTerm.php'); +require_once(CONST_LibDir.'/TokenWord.php'); +require_once(CONST_LibDir.'/SpecialSearchOperator.php'); /** * Saves information about the tokens that appear in a search query. diff --git a/lib/TokenSpecialTerm.php b/lib/TokenSpecialTerm.php index 64e4b3d4..b2c312ec 100644 --- a/lib/TokenSpecialTerm.php +++ b/lib/TokenSpecialTerm.php @@ -2,7 +2,7 @@ namespace Nominatim\Token; -require_once(CONST_BasePath.'/lib/SpecialSearchOperator.php'); +require_once(CONST_LibDir.'/SpecialSearchOperator.php'); /** * A word token describing a place type. diff --git a/lib/cmd.php b/lib/cmd.php index 72b66608..5a12f99a 100644 --- a/lib/cmd.php +++ b/lib/cmd.php @@ -1,6 +1,6 @@ $sProxy, + 'request_fulluri' => true, + 'header' => $aHeaders + ); + + $aContext = array('http' => $aProxyHeader, 'https' => $aProxyHeader); + stream_context_set_default($aContext); +} diff --git a/lib/init-cmd.php b/lib/init-cmd.php index 50c709c9..b7645cd5 100644 --- a/lib/init-cmd.php +++ b/lib/init-cmd.php @@ -3,26 +3,3 @@ require_once('init.php'); require_once('cmd.php'); require_once('DebugNone.php'); - -// handle http proxy when using file_get_contents -if (CONST_HTTP_Proxy) { - $proxy = 'tcp://' . CONST_HTTP_Proxy_Host . ':' . CONST_HTTP_Proxy_Port; - $aHeaders = array(); - if (CONST_HTTP_Proxy_Login != null && CONST_HTTP_Proxy_Login != '' && CONST_HTTP_Proxy_Password != null && CONST_HTTP_Proxy_Password != '') { - $auth = base64_encode(CONST_HTTP_Proxy_Login . ':' . CONST_HTTP_Proxy_Password); - $aHeaders = array("Proxy-Authorization: Basic $auth"); - } - $aContext = array( - 'http' => array( - 'proxy' => $proxy, - 'request_fulluri' => true, - 'header' => $aHeaders - ), - 'https' => array( - 'proxy' => $proxy, - 'request_fulluri' => true, - 'header' => $aHeaders - ) - ); - stream_context_set_default($aContext); -} diff --git a/lib/init-website.php b/lib/init-website.php index 302a9478..f2d52980 100644 --- a/lib/init-website.php +++ b/lib/init-website.php @@ -20,7 +20,7 @@ function exception_handler_json($exception) { http_response_code($exception->getCode()); header('Content-type: application/json; charset=utf-8'); - include(CONST_BasePath.'/lib/template/error-json.php'); + include(CONST_LibDir.'/template/error-json.php'); exit(); } @@ -29,7 +29,7 @@ function exception_handler_xml($exception) http_response_code($exception->getCode()); header('Content-type: text/xml; charset=utf-8'); echo ''."\n"; - include(CONST_BasePath.'/lib/template/error-xml.php'); + include(CONST_LibDir.'/template/error-xml.php'); exit(); } diff --git a/lib/init.php b/lib/init.php index 082d1bf5..cc50aaf3 100644 --- a/lib/init.php +++ b/lib/init.php @@ -1,4 +1,4 @@ load(CONST_DataDir.'/settings/env.defaults'); + + if (file_exists($sProjectDir.'/.env')) { + $dotenv->load($sProjectDir.'/.env'); + } +} + +function getSetting($sConfName, $sDefault = null) +{ + $sValue = $_SERVER['NOMINATIM_'.$sConfName]; + + if ($sDefault !== null && !$sValue) { + return $sDefault; + } + + return $sValue; +} + +function getSettingBool($sConfName) +{ + $sVal = strtolower(getSetting($sConfName)); + + return strcmp($sVal, 'yes') == 0 + || strcmp($sVal, 'true') == 0 + || strcmp($sVal, '1') == 0; +} + +function getSettingConfig($sConfName, $sSystemConfig) +{ + $sValue = $_ENV['NOMINATIM_'.$sConfName]; + + if (!$sValue) { + return CONST_DataDir.'/settings/'.$sSystemConfig; + } + + return $sValue; +} + function fail($sError, $sUserError = false) { if (!$sUserError) $sUserError = $sError; @@ -89,6 +134,24 @@ function addQuotes($s) return "'".$s."'"; } +function fwriteConstDef($rFile, $sConstName, $value) +{ + $sEscapedValue; + + if (is_bool($value)) { + $sEscapedValue = $value ? 'true' : 'false'; + } elseif (is_numeric($value)) { + $sEscapedValue = strval($value); + } elseif (!$value) { + $sEscapedValue = 'false'; + } else { + $sEscapedValue = addQuotes(str_replace("'", "\\'", (string)$value)); + } + + fwrite($rFile, "@define('CONST_$sConstName', $sEscapedValue);\n"); +} + + function parseLatLon($sQuery) { $sFound = null; diff --git a/lib/setup/SetupClass.php b/lib/setup/SetupClass.php index f16c9e60..d3c4c4eb 100755 --- a/lib/setup/SetupClass.php +++ b/lib/setup/SetupClass.php @@ -2,8 +2,8 @@ namespace Nominatim\Setup; -require_once(CONST_BasePath.'/lib/setup/AddressLevelParser.php'); -require_once(CONST_BasePath.'/lib/Shell.php'); +require_once(CONST_LibDir.'/setup/AddressLevelParser.php'); +require_once(CONST_LibDir.'/Shell.php'); class SetupFunctions { @@ -34,7 +34,7 @@ class SetupFunctions if (isset($aCMDResult['osm2pgsql-cache'])) { $this->iCacheMemory = $aCMDResult['osm2pgsql-cache']; - } elseif (!is_null(CONST_Osm2pgsql_Flatnode_File)) { + } elseif (getSetting('FLATNODE_FILE')) { // When flatnode files are enabled then disable cache per default. $this->iCacheMemory = 0; } else { @@ -42,11 +42,11 @@ class SetupFunctions $this->iCacheMemory = getCacheMemoryMB(); } - $this->sModulePath = CONST_Database_Module_Path; + $this->sModulePath = getSetting('DATABASE_MODULE_PATH', CONST_InstallDir.'/module'); info('module path: ' . $this->sModulePath); // parse database string - $this->aDSNInfo = \Nominatim\DB::parseDSN(CONST_Database_DSN); + $this->aDSNInfo = \Nominatim\DB::parseDSN(getSetting('DATABASE_DSN')); if (!isset($this->aDSNInfo['port'])) { $this->aDSNInfo['port'] = 5432; } @@ -86,7 +86,7 @@ class SetupFunctions $oDB = new \Nominatim\DB; if ($oDB->checkConnection()) { - fail('database already exists ('.CONST_Database_DSN.')'); + fail('database already exists ('.getSetting('DATABASE_DSN').')'); } $oCmd = (new \Nominatim\Shell('createdb')) @@ -130,34 +130,35 @@ class SetupFunctions exit(1); } - $i = $this->db()->getOne("select count(*) from pg_user where usename = '".CONST_Database_Web_User."'"); + $sPgUser = getSetting('DATABASE_WEBUSER'); + $i = $this->db()->getOne("select count(*) from pg_user where usename = '$sPgUser'"); if ($i == 0) { - echo "\nERROR: Web user '".CONST_Database_Web_User."' does not exist. Create it with:\n"; - echo "\n createuser ".CONST_Database_Web_User."\n\n"; + echo "\nERROR: Web user '".$sPgUser."' does not exist. Create it with:\n"; + echo "\n createuser ".$sPgUser."\n\n"; exit(1); } // Try accessing the C module, so we know early if something is wrong - checkModulePresence(); // raises exception on failure + $this->checkModulePresence(); // raises exception on failure - if (!file_exists(CONST_ExtraDataPath.'/country_osm_grid.sql.gz')) { + if (!file_exists(CONST_DataDir.'/data/country_osm_grid.sql.gz')) { echo 'Error: you need to download the country_osm_grid first:'; - echo "\n wget -O ".CONST_ExtraDataPath."/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz\n"; + echo "\n wget -O ".CONST_DataDir."/data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz\n"; exit(1); } - $this->pgsqlRunScriptFile(CONST_BasePath.'/data/country_name.sql'); - $this->pgsqlRunScriptFile(CONST_ExtraDataPath.'/country_osm_grid.sql.gz'); - $this->pgsqlRunScriptFile(CONST_BasePath.'/data/gb_postcode_table.sql'); - $this->pgsqlRunScriptFile(CONST_BasePath.'/data/us_postcode_table.sql'); + $this->pgsqlRunScriptFile(CONST_DataDir.'/data/country_name.sql'); + $this->pgsqlRunScriptFile(CONST_DataDir.'/data/country_osm_grid.sql.gz'); + $this->pgsqlRunScriptFile(CONST_DataDir.'/data/gb_postcode_table.sql'); + $this->pgsqlRunScriptFile(CONST_DataDir.'/data/us_postcode_table.sql'); - $sPostcodeFilename = CONST_BasePath.'/data/gb_postcode_data.sql.gz'; + $sPostcodeFilename = CONST_DataDir.'/data/gb_postcode_data.sql.gz'; if (file_exists($sPostcodeFilename)) { $this->pgsqlRunScriptFile($sPostcodeFilename); } else { warn('optional external GB postcode table file ('.$sPostcodeFilename.') not found. Skipping.'); } - $sPostcodeFilename = CONST_BasePath.'/data/us_postcode_data.sql.gz'; + $sPostcodeFilename = CONST_DataDir.'/data/us_postcode_data.sql.gz'; if (file_exists($sPostcodeFilename)) { $this->pgsqlRunScriptFile($sPostcodeFilename); } else { @@ -173,29 +174,29 @@ class SetupFunctions { info('Import data'); - if (!file_exists(CONST_Osm2pgsql_Binary)) { - echo "Check CONST_Osm2pgsql_Binary in your local settings file.\n"; + if (!file_exists(getOsm2pgsqlBinary())) { + echo "Check NOMINATIM_OSM2PGSQL_BINARY in your local .env file.\n"; echo "Normally you should not need to set this manually.\n"; - fail("osm2pgsql not found in '".CONST_Osm2pgsql_Binary."'"); + fail("osm2pgsql not found in '".getOsm2pgsqlBinary()."'"); } - $oCmd = new \Nominatim\Shell(CONST_Osm2pgsql_Binary); - $oCmd->addParams('--style', CONST_Import_Style); + $oCmd = new \Nominatim\Shell(getOsm2pgsqlBinary()); + $oCmd->addParams('--style', getImportStyle()); - if (!is_null(CONST_Osm2pgsql_Flatnode_File) && CONST_Osm2pgsql_Flatnode_File) { - $oCmd->addParams('--flat-nodes', CONST_Osm2pgsql_Flatnode_File); + if (getSetting('FLATNODE_FILE')) { + $oCmd->addParams('--flat-nodes', getSetting('FLATNODE_FILE')); } - if (CONST_Tablespace_Osm2pgsql_Data) { - $oCmd->addParams('--tablespace-slim-data', CONST_Tablespace_Osm2pgsql_Data); + if (getSetting('TABLESPACE_OSM_DATA')) { + $oCmd->addParams('--tablespace-slim-data', getSetting('TABLESPACE_OSM_DATA')); } - if (CONST_Tablespace_Osm2pgsql_Index) { - $oCmd->addParams('--tablespace-slim-index', CONST_Tablespace_Osm2pgsql_Index); + if (getSetting('TABLESPACE_OSM_INDEX')) { + $oCmd->addParams('--tablespace-slim-index', getSetting('TABLESPACE_OSM_INDEX')); } - if (CONST_Tablespace_Place_Data) { - $oCmd->addParams('--tablespace-main-data', CONST_Tablespace_Place_Data); + if (getSetting('TABLESPACE_PLACE_DATA')) { + $oCmd->addParams('--tablespace-main-data', getSetting('TABLESPACE_PLACE_DATA')); } - if (CONST_Tablespace_Place_Index) { - $oCmd->addParams('--tablespace-main-index', CONST_Tablespace_Place_Index); + if (getSetting('TABLESPACE_PLACE_INDEX')) { + $oCmd->addParams('--tablespace-main-index', getSetting('TABLESPACE_PLACE_INDEX')); } $oCmd->addParams('--latlong', '--slim', '--create'); $oCmd->addParams('--output', 'gazetteer'); @@ -234,7 +235,7 @@ class SetupFunctions info('Create Functions'); // Try accessing the C module, so we know early if something is wrong - checkModulePresence(); // raises exception on failure + $this->checkModulePresence(); // raises exception on failure $this->createSqlFunctions(); } @@ -243,7 +244,7 @@ class SetupFunctions { info('Create Tables'); - $sTemplate = file_get_contents(CONST_BasePath.'/sql/tables.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/tables.sql'); $sTemplate = $this->replaceSqlPatterns($sTemplate); $this->pgsqlRunScript($sTemplate, false); @@ -252,7 +253,7 @@ class SetupFunctions $this->dropTable('search_name'); } - $oAlParser = new AddressLevelParser(CONST_Address_Level_Config); + $oAlParser = new AddressLevelParser(getSettingConfig('ADDRESS_LEVEL_CONFIG', 'address-levels.json')); $oAlParser->createTable($this->db(), 'address_levels'); } @@ -260,7 +261,7 @@ class SetupFunctions { info('Create Tables'); - $sTemplate = file_get_contents(CONST_BasePath.'/sql/table-triggers.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/table-triggers.sql'); $sTemplate = $this->replaceSqlPatterns($sTemplate); $this->pgsqlRunScript($sTemplate, false); @@ -270,7 +271,7 @@ class SetupFunctions { info('Create Partition Tables'); - $sTemplate = file_get_contents(CONST_BasePath.'/sql/partition-tables.src.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/partition-tables.src.sql'); $sTemplate = $this->replaceSqlPatterns($sTemplate); $this->pgsqlRunPartitionScript($sTemplate); @@ -280,13 +281,14 @@ class SetupFunctions { info('Create Partition Functions'); - $sTemplate = file_get_contents(CONST_BasePath.'/sql/partition-functions.src.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/partition-functions.src.sql'); $this->pgsqlRunPartitionScript($sTemplate); } public function importWikipediaArticles() { - $sWikiArticlesFile = CONST_Wikipedia_Data_Path.'/wikimedia-importance.sql.gz'; + $sWikiArticlePath = getSetting('WIKIPEDIA_DATA_PATH', CONST_DataDir.'/data'); + $sWikiArticlesFile = $sWikiArticlePath.'/wikimedia-importance.sql.gz'; if (file_exists($sWikiArticlesFile)) { info('Importing wikipedia articles and redirects'); $this->dropTable('wikipedia_article'); @@ -335,14 +337,14 @@ class SetupFunctions // used by getorcreate_word_id to ignore frequent partial words $sSQL = 'CREATE OR REPLACE FUNCTION get_maxwordfreq() RETURNS integer AS '; - $sSQL .= '$$ SELECT '.CONST_Max_Word_Frequency.' as maxwordfreq; $$ LANGUAGE SQL IMMUTABLE'; + $sSQL .= '$$ SELECT '.getSetting('MAX_WORD_FREQUENCY').' as maxwordfreq; $$ LANGUAGE SQL IMMUTABLE'; $oDB->exec($sSQL); echo ".\n"; // pre-create the word list if (!$bDisableTokenPrecalc) { info('Loading word list'); - $this->pgsqlRunScriptFile(CONST_BasePath.'/data/words.sql'); + $this->pgsqlRunScriptFile(CONST_DataDir.'/data/words.sql'); } info('Load Data'); @@ -352,7 +354,7 @@ class SetupFunctions $iLoadThreads = max(1, $this->iInstances - 1); for ($i = 0; $i < $iLoadThreads; $i++) { // https://secure.php.net/manual/en/function.pg-connect.php - $DSN = CONST_Database_DSN; + $DSN = getSetting('DATABASE_DSN'); $DSN = preg_replace('/^pgsql:/', '', $DSN); $DSN = preg_replace('/;/', ' ', $DSN); $aDBInstances[$i] = pg_connect($DSN, PGSQL_CONNECT_FORCE_NEW); @@ -372,7 +374,7 @@ class SetupFunctions // last thread for interpolation lines // https://secure.php.net/manual/en/function.pg-connect.php - $DSN = CONST_Database_DSN; + $DSN = getSetting('DATABASE_DSN'); $DSN = preg_replace('/^pgsql:/', '', $DSN); $DSN = preg_replace('/;/', ' ', $DSN); $aDBInstances[$iLoadThreads] = pg_connect($DSN, PGSQL_CONNECT_FORCE_NEW); @@ -424,17 +426,17 @@ class SetupFunctions } } - public function importTigerData() + public function importTigerData($sTigerPath) { info('Import Tiger data'); - $aFilenames = glob(CONST_Tiger_Data_Path.'/*.sql'); - info('Found '.count($aFilenames).' SQL files in path '.CONST_Tiger_Data_Path); + $aFilenames = glob($sTigerPath.'/*.sql'); + info('Found '.count($aFilenames).' SQL files in path '.$sTigerPath); if (empty($aFilenames)) { - warn('Tiger data import selected but no files found in path '.CONST_Tiger_Data_Path); + warn('Tiger data import selected but no files found in path '.$sTigerPath); return; } - $sTemplate = file_get_contents(CONST_BasePath.'/sql/tiger_import_start.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/tiger_import_start.sql'); $sTemplate = $this->replaceSqlPatterns($sTemplate); $this->pgsqlRunScript($sTemplate, false); @@ -442,7 +444,7 @@ class SetupFunctions $aDBInstances = array(); for ($i = 0; $i < $this->iInstances; $i++) { // https://secure.php.net/manual/en/function.pg-connect.php - $DSN = CONST_Database_DSN; + $DSN = getSetting('DATABASE_DSN'); $DSN = preg_replace('/^pgsql:/', '', $DSN); $DSN = preg_replace('/;/', ' ', $DSN); $aDBInstances[$i] = pg_connect($DSN, PGSQL_CONNECT_FORCE_NEW | PGSQL_CONNECT_ASYNC); @@ -488,7 +490,7 @@ class SetupFunctions } info('Creating indexes on Tiger data'); - $sTemplate = file_get_contents(CONST_BasePath.'/sql/tiger_import_finish.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/tiger_import_finish.sql'); $sTemplate = $this->replaceSqlPatterns($sTemplate); $this->pgsqlRunScript($sTemplate, false); @@ -542,9 +544,9 @@ class SetupFunctions public function index($bIndexNoanalyse) { - checkModulePresence(); // raises exception on failure + $this->checkModulePresence(); // raises exception on failure - $oBaseCmd = (new \Nominatim\Shell(CONST_BasePath.'/nominatim/nominatim.py')) + $oBaseCmd = (new \Nominatim\Shell(CONST_DataDir.'/nominatim/nominatim.py')) ->addParams('--database', $this->aDSNInfo['database']) ->addParams('--port', $this->aDSNInfo['port']) ->addParams('--threads', $this->iInstances); @@ -616,12 +618,12 @@ class SetupFunctions $this->db()->exec("DROP INDEX $sIndexName;"); } - $sTemplate = file_get_contents(CONST_BasePath.'/sql/indices.src.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/indices.src.sql'); if (!$this->bDrop) { - $sTemplate .= file_get_contents(CONST_BasePath.'/sql/indices_updates.src.sql'); + $sTemplate .= file_get_contents(CONST_DataDir.'/sql/indices_updates.src.sql'); } if (!$this->dbReverseOnly()) { - $sTemplate .= file_get_contents(CONST_BasePath.'/sql/indices_search.src.sql'); + $sTemplate .= file_get_contents(CONST_DataDir.'/sql/indices_search.src.sql'); } $sTemplate = $this->replaceSqlPatterns($sTemplate); @@ -638,10 +640,11 @@ class SetupFunctions $this->pgsqlRunScript("select count(*) from (select getorcreate_country(make_standard_name(name->'name'), country_code) from country_name where name ? 'name') as x"); $sSQL = 'select count(*) from (select getorcreate_country(make_standard_name(v),' .'country_code) from (select country_code, skeys(name) as k, svals(name) as v from country_name) x where k '; - if (CONST_Languages) { + $sLanguages = getSetting('LANGUAGES'); + if ($sLanguages) { $sSQL .= 'in '; $sDelim = '('; - foreach (explode(',', CONST_Languages) as $sLang) { + foreach (explode(',', $sLanguages) as $sLang) { $sSQL .= $sDelim."'name:$sLang'"; $sDelim = ','; } @@ -703,36 +706,60 @@ class SetupFunctions } /** - * Setup settings-frontend.php in the build/website directory + * Setup the directory for the API scripts. * * @return null */ public function setupWebsite() { - $rOutputFile = fopen(CONST_InstallPath.'/settings/settings-frontend.php', 'w'); - - fwrite($rOutputFile, "bVerbose) echo 'Deleting '.CONST_Osm2pgsql_Flatnode_File."\n"; - unlink(CONST_Osm2pgsql_Flatnode_File); - } + $sFName = getSetting('FLATNODE_FILE'); + if ($sFName && file_exists($sFName)) { + if ($this->bVerbose) echo 'Deleting '.$sFName."\n"; + unlink($sFName); } } @@ -775,7 +801,7 @@ if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SE private function createSqlFunctions() { - $sBasePath = CONST_BasePath.'/sql/functions/'; + $sBasePath = CONST_DataDir.'/sql/functions/'; $sTemplate = file_get_contents($sBasePath.'utils.sql'); $sTemplate .= file_get_contents($sBasePath.'normalization.sql'); $sTemplate .= file_get_contents($sBasePath.'ranking.sql'); @@ -798,13 +824,13 @@ if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SE if ($this->bEnableDebugStatements) { $sTemplate = str_replace('--DEBUG:', '', $sTemplate); } - if (CONST_Limit_Reindexing) { + if (getSettingBool('LIMIT_REINDEXING')) { $sTemplate = str_replace('--LIMIT INDEXING:', '', $sTemplate); } - if (!CONST_Use_US_Tiger_Data) { + if (!getSettingBool('USE_US_TIGER_DATA')) { $sTemplate = str_replace('-- %NOTIGERDATA% ', '', $sTemplate); } - if (!CONST_Use_Aux_Location_data) { + if (!getSettingBool('USE_AUX_LOCATION_DATA')) { $sTemplate = str_replace('-- %NOAUXDATA% ', '', $sTemplate); } @@ -895,15 +921,15 @@ if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SE private function replaceSqlPatterns($sSql) { - $sSql = str_replace('{www-user}', CONST_Database_Web_User, $sSql); + $sSql = str_replace('{www-user}', getSetting('DATABASE_WEBUSER'), $sSql); $aPatterns = array( - '{ts:address-data}' => CONST_Tablespace_Address_Data, - '{ts:address-index}' => CONST_Tablespace_Address_Index, - '{ts:search-data}' => CONST_Tablespace_Search_Data, - '{ts:search-index}' => CONST_Tablespace_Search_Index, - '{ts:aux-data}' => CONST_Tablespace_Aux_Data, - '{ts:aux-index}' => CONST_Tablespace_Aux_Index, + '{ts:address-data}' => getSetting('TABLESPACE_ADDRESS_DATA'), + '{ts:address-index}' => getSetting('TABLESPACE_ADDRESS_INDEX'), + '{ts:search-data}' => getSetting('TABLESPACE_SEARCH_DATA'), + '{ts:search-index}' => getSetting('TABLESPACE_SEARCH_INDEX'), + '{ts:aux-data}' => getSetting('TABLESPACE_AUX_DATA'), + '{ts:aux-index}' => getSetting('TABLESPACE_AUX_INDEX') ); foreach ($aPatterns as $sPattern => $sTablespace) { @@ -939,4 +965,20 @@ if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SE { return !($this->db()->tableExists('search_name')); } + + /** + * Try accessing the C module, so we know early if something is wrong. + * + * Raises Nominatim\DatabaseError on failure + */ + private function checkModulePresence() + { + $sSQL = "CREATE FUNCTION nominatim_test_import_func(text) RETURNS text AS '"; + $sSQL .= $this->sModulePath . "/nominatim.so', 'transliteration' LANGUAGE c IMMUTABLE STRICT"; + $sSQL .= ';DROP FUNCTION nominatim_test_import_func(text);'; + + $oDB = new \Nominatim\DB(); + $oDB->connect(); + $oDB->exec($sSQL, null, 'Database server failed to load '.$this->sModulePath.'/nominatim.so module'); + } } diff --git a/lib/setup_functions.php b/lib/setup_functions.php index 43f30a09..a2287d9b 100755 --- a/lib/setup_functions.php +++ b/lib/setup_functions.php @@ -15,17 +15,23 @@ function checkInFile($sOSMFile) } } -function checkModulePresence() +function getOsm2pgsqlBinary() { - // Try accessing the C module, so we know early if something is wrong. - // Raises Nominatim\DatabaseError on failure + $sBinary = getSetting('OSM2PGSQL_BINARY'); + if (!$sBinary) { + $sBinary = CONST_InstallDir.'/osm2pgsql/osm2pgsql'; + } + + return $sBinary; +} - $sModulePath = CONST_Database_Module_Path; - $sSQL = "CREATE FUNCTION nominatim_test_import_func(text) RETURNS text AS '"; - $sSQL .= $sModulePath . "/nominatim.so', 'transliteration' LANGUAGE c IMMUTABLE STRICT"; - $sSQL .= ';DROP FUNCTION nominatim_test_import_func(text);'; +function getImportStyle() +{ + $sStyle = getSetting('IMPORT_STYLE'); + + if (in_array($sStyle, array('admin', 'street', 'address', 'full', 'extratags'))) { + return CONST_DataDir.'/settings/import-'.$sStyle.'.style'; + } - $oDB = new \Nominatim\DB(); - $oDB->connect(); - $oDB->exec($sSQL, null, 'Database server failed to load '.$sModulePath.'/nominatim.so module'); + return $sStyle; } diff --git a/settings/defaults.php b/settings/defaults.php deleted file mode 100644 index 2ecbb514..00000000 --- a/settings/defaults.php +++ /dev/null @@ -1,118 +0,0 @@ -; :: lower (); [[:Punctuation:][:Space:]]+ > ' '; :: NFC ();"); - -/* Set to true after importing Tiger house number data for the US. - Note: The tables must already exist or queries will throw errors. - After changing this setting run ./utils/setup --create-functions - again. */ -@define('CONST_Use_US_Tiger_Data', false); -/* Set to true after importing other external house number data. - Note: the aux tables must already exist or queries will throw errors. - After changing this setting run ./utils/setup --create-functions - again. */ -@define('CONST_Use_Aux_Location_data', false); - -// Proxy settings -@define('CONST_HTTP_Proxy', false); -@define('CONST_HTTP_Proxy_Host', 'proxy.mydomain.com'); -@define('CONST_HTTP_Proxy_Port', '3128'); -@define('CONST_HTTP_Proxy_Login', ''); -@define('CONST_HTTP_Proxy_Password', ''); - -// Paths -@define('CONST_ExtraDataPath', CONST_BasePath.'/data'); -@define('CONST_Osm2pgsql_Binary', CONST_InstallPath.'/osm2pgsql/osm2pgsql'); -@define('CONST_Pyosmium_Binary', '@PYOSMIUM_PATH@'); -@define('CONST_Tiger_Data_Path', CONST_ExtraDataPath.'/tiger'); -@define('CONST_Wikipedia_Data_Path', CONST_ExtraDataPath); -@define('CONST_Phrase_Config', CONST_BasePath.'/settings/phrase_settings.php'); -@define('CONST_Address_Level_Config', CONST_BasePath.'/settings/address-levels.json'); -@define('CONST_Import_Style', CONST_BasePath.'/settings/import-full.style'); - -// osm2pgsql settings -@define('CONST_Osm2pgsql_Flatnode_File', null); - -// tablespace settings -// osm2pgsql caching tables (aka slim mode tables) - update only -@define('CONST_Tablespace_Osm2pgsql_Data', false); -@define('CONST_Tablespace_Osm2pgsql_Index', false); -// osm2pgsql output tables (aka main table) - update only -@define('CONST_Tablespace_Place_Data', false); -@define('CONST_Tablespace_Place_Index', false); -// address computation tables - update only -@define('CONST_Tablespace_Address_Data', false); -@define('CONST_Tablespace_Address_Index', false); -// search tables - needed for lookups -@define('CONST_Tablespace_Search_Data', false); -@define('CONST_Tablespace_Search_Index', false); -// additional data, e.g. TIGER data, type searches - needed for lookups -@define('CONST_Tablespace_Aux_Data', false); -@define('CONST_Tablespace_Aux_Index', false); - -//// Replication settings - -// Base URL of replication service -@define('CONST_Replication_Url', 'https://planet.openstreetmap.org/replication/minute'); - -// Maximum size in MB of data to download per batch -@define('CONST_Replication_Max_Diff_size', '30'); -// How long until the service publishes the next diff -// (relative to the age of data in the diff). -@define('CONST_Replication_Update_Interval', '75'); -// How long to sleep when no update could be found -@define('CONST_Replication_Recheck_Interval', '60'); - -// If true, send CORS headers to allow access -@define('CONST_NoAccessControl', true); - -// Set this to the /mapicon directory of your nominatim-ui to enable returning -// icon URLs with the results. -@define('CONST_MapIcon_URL', false); -// Language to assume when none is supplied with the query. -// When set to false, the local language (i.e. the name tag without suffix) -// will be used. -@define('CONST_Default_Language', false); - -@define('CONST_Search_AreaPolygons', true); - -@define('CONST_Search_BatchMode', false); - -@define('CONST_Search_NameOnlySearchFrequencyThreshold', 500); -// If set to true, then reverse order of queries will be tried by default. -// When set to false only selected languages allow reverse search. -@define('CONST_Search_ReversePlanForAll', true); - -// Maximum number of OSM ids that may be queried at once -// for the places endpoint. -@define('CONST_Places_Max_ID_count', 50); - -// Number of different geometry formats that may be queried in parallel. -// Set to zero to disable polygon output. -@define('CONST_PolygonOutput_MaximumTypes', 1); - -// Log settings -// Set to true to log into new_query_log table. -// You should set up a cron job that regularly clears out this table. -@define('CONST_Log_DB', false); -// Set to a file name to enable logging to a file. -@define('CONST_Log_File', false); diff --git a/settings/env.defaults b/settings/env.defaults new file mode 100644 index 00000000..fbad3e33 --- /dev/null +++ b/settings/env.defaults @@ -0,0 +1,213 @@ +# .env +# Default configuration settings for Nominatim. +# This file uses the dotenv format. + +# Database connection string. +# Add host, port, user etc through additional semicolon-separated attributes. +# e.g. ;host=...;port=...;user=...;password=... +# Changing this variable requires to run 'setup.php --setup-website'. +NOMINATIM_DATABASE_DSN="pgsql:dbname=nominatim" + +# Database web user. +# Nominatim sets up read-only access for this user during installation. +NOMINATIM_DATABASE_WEBUSER="www-data" + +# Directory where to find the PostgreSQL server module. +# When empty the module is expected to be located in the 'module' subdirectory +# in the project directory. +# Changing this value requires to run ./utils/setup --create-functions. +NOMINATIM_DATABASE_MODULE_PATH= + +# Number of occurances of a word before it is considered frequent. +# Similar to the concept of stop words. Frequent partial words get ignored +# or handled differently during search. +# Changing this value requires a reimport. +NOMINATIM_MAX_WORD_FREQUENCY=50000 + +# If true, admin level changes on places with many contained children are blocked. +NOMINATIM_LIMIT_REINDEXING=yes + +# Restrict search languages. +# Normally Nominatim will include all language variants of name:XX +# in the search index. Set this to a comma separated list of language +# codes, to restrict import to a subset of languages. +# Currently only affects the initial import of country names and special phrases. +NOMINATIM_LANGUAGES= + +# Rules for normalizing terms for comparisons. +# The default is to remove accents and punctuation and to lower-case the +# term. Spaces are kept but collapsed to one standard space. +# Changing this value requires a reimport. +NOMINATIM_TERM_NORMALIZATION=":: NFD (); [[:Nonspacing Mark:] [:Cf:]] >; :: lower (); [[:Punctuation:][:Space:]]+ > ' '; :: NFC ();" + +# Search in the Tiger house number data for the US. +# Note: The tables must already exist or queries will throw errors. +# Changing this value requires to run ./utils/setup --create-functions --setup-website. +NOMINATIM_USE_US_TIGER_DATA=no + +# Search in the auxilary housenumber table. +# Changing this value requires to run ./utils/setup --create-functions --setup-website. +NOMINATIM_USE_AUX_LOCATION_DATA=no + +# Proxy settings +# The following settings allow to set a proxy to use when remotely downloading +# data. Host and port are required. Login and password are optional. +NOMINATIM_HTTP_PROXY=no +NOMINATIM_HTTP_PROXY_HOST=proxy.mydomain.com +NOMINATIM_HTTP_PROXY_PORT=3128 +NOMINATIM_HTTP_PROXY_LOGIN= +NOMINATIM_HTTP_PROXY_PASSWORD= + +# Location of the osm2pgsql binary. +# When empty, osm2pgsql is expected to reside in the osm2pgsql directory in +# the project directory. +# EXPERT ONLY. You should usually use the supplied osm2pgsql. +NOMINATIM_OSM2PGSQL_BINARY= + +# Location of pyosmium-get-changes. +# Only needed when running updates. +NOMINATIM_PYOSMIUM_BINARY= + +# Directory where to find US Tiger data files to import. +# Used with setup.php --import-tiger-data. When unset, the data is expected +# to be located under 'data/tiger' in the source tree. +NOMINATIM_TIGER_DATA_PATH= + +# Directory where to find pre-computed Wikipedia importance files. +# When unset, the data is expected to be located in the 'data' directory +# in the source tree. +NOMINATIM_WIKIPEDIA_DATA_PATH= + +# Configuration file for special phrase import. +# When unset, the internal default settings from 'settings/phrase_settings.php' +# are used. +NOMINATIM_PHRASE_CONFIG= + +# Configuration file for rank assignments. +# When unset, the internal default settings from 'settings/address-levels.json' +# are used. +NOMINATIM_ADDRESS_LEVEL_CONFIG= + +# Configuration file for OSM data import. +# This may either be the name of one of an internal style or point +# to a file with a custom style. +# Internal styles are: admin, street, address, full, extratags +NOMINATIM_IMPORT_STYLE=extratags + +# Location of the flatnode file used by osm2pgsql to store node locations. +# When unset, osm2pgsql stores the location in the PostgreSQL database. This +# is especially useful for imports of larger areas, like continents or the +# full planet. The file needs at least 70GB storage. +NOMINATIM_FLATNODE_FILE= + +### Tablespace settings +# +# The following settings allow to move parts of the database tables into +# different tablespaces. This is especially interesting if you have disks +# with different speeds. When unset, the default tablespace is used. +# Only has an effect during import. + +# Tablespace used for tables used when searching. +NOMINATIM_TABLESPACE_SEARCH_DATA= +# Tablespace used for indexes used when searching. +NOMINATIM_TABLESPACE_SEARCH_INDEX= + +# Tablespace used for the OSM data cache tables. Used for import and update only. +NOMINATIM_TABLESPACE_OSM_DATA= +# Tablespace used for the OSM data cache indexes. Used for import and update only. +NOMINATIM_TABLESPACE_OSM_INDEX= + +# Tablespace used for place import table. Used for import and update only. +NOMINATIM_TABLESPACE_PLACE_DATA= +# Tablespace used for place import indexes. Used for import and update only. +NOMINATIM_TABLESPACE_PLACE_INDEX= + +# Tablespace for tables used during address computation. Used for import and update only. +NOMINATIM_TABLESPACE_ADDRESS_DATA= +# Tablespace for indexes used during address computation. Used for import and update only. +NOMINATIM_TABLESPACE_ADDRESS_INDEX= + +# Tablespace for tables for auxilary data, e.g. TIGER data, postcodes. +NOMINATIM_TABLESPACE_AUX_DATA= +# Tablespace for indexes for auxilary data, e.g. TIGER data, postcodes. +NOMINATIM_TABLESPACE_AUX_INDEX= + + +### Replication settings +# +# The following settings control where and how updates for the database are +# retrieved. +# + +# +# Base URL of replication service. +# A replication service provides change files of OSM data at regular intervals. +# These are used to keep the database up to date. Per default it points to +# the minutely updates for the main OSM database. There are other services +# geared towards larger update intervals or data extracts. +# Changing this value requires to rerun 'update/php --init-updates'. +NOMINATIM_REPLICATION_URL="https://planet.openstreetmap.org/replication/minute" + +# Maximum amount of data to download per batch. +# Size is in MB. +NOMINATIM_REPLICATION_MAX_DIFF=50 + +# Publication interval of the replication service. +# Determines when Nominatim will attempt again to download again a new +# update. The time is computed from the publication date of the last diff +# downloaded. Setting this to a slightly higher value than the actual +# publication interval avoids unnecessary rechecks. +NOMINATIM_REPLICATION_UPDATE_INTERVAL=75 + +# Wait time to recheck for a pending update. +# Time to wait after an expected update was not available on the server. +NOMINATIM_REPLICATION_RECHECK_INTERVAL=60 + +### API settings +# +# The following settings configure the API responses. You must rerun +# setup.php --setup-website after changing any of them. + +# Send permissive CORS access headers. +# When enabled, send CORS headers to allow access to everybody. +NOMINATIM_CORS_NOACCESSCONTROL=yes + +# URL for static icon images. +# Set this to the /mapicon directory of your nominatim-ui to enable returning +# icon URLs with the results. +NOMINATIM_MAPICON_URL= + +# Language to assume when no particular language is requested. +# When unset, the local language (i.e. the name tag without suffix) will be used. +NOMINATIM_DEFAULT_LANGUAGE= + +# Enable a special batch query mode. +# This features is currently undocumented and potentially broken. +NOMINATIM_SEARCH_BATCH_MODE=no + +# Threshold for searches by name only. +# Threshold where the lookup strategy in the database is switched. If there +# are less occurences of a tem than given, the search does the lookup only +# against the name, otherwise it uses indexes for name and address. +NOMINATIM_SEARCH_NAME_ONLY_THRESHOLD=500 + +# Maximum number of OSM ids accepted by /lookup. +NOMINATIM_LOOKUP_MAX_COUNT=50 + +# Number of different geometry formats that may be queried in parallel. +# Set to zero to disable polygon output. +NOMINATIM_POLYGON_OUTPUT_MAX_TYPES=1 + +### Log settings +# +# The following options allow to enable logging of API requests. +# You must rerun setup.php --setup-website after changing any of them. +# +# Enable logging of requests into the DB. +# The request will be logged into the new_query_log table. +# You should set up a cron job that regularly clears out this table. +NOMINATIM_LOG_DB=no + +# Enable logging of requests into a file. +# To enable logging set this setting to the file to log to. +NOMINATIM_LOG_FILE= diff --git a/sql/functions/address_lookup.sql b/sql/functions/address_lookup.sql index a2b7c90a..b832aed8 100644 --- a/sql/functions/address_lookup.sql +++ b/sql/functions/address_lookup.sql @@ -79,6 +79,18 @@ END; $$ LANGUAGE plpgsql STABLE; +DROP TYPE IF EXISTS addressdata_place; +CREATE TYPE addressdata_place AS ( + place_id BIGINT, + country_code VARCHAR(2), + housenumber TEXT, + postcode TEXT, + class TEXT, + type TEXT, + name HSTORE, + address HSTORE, + centroid GEOMETRY +); -- Compute the list of address parts for the given place. -- @@ -87,7 +99,7 @@ CREATE OR REPLACE FUNCTION get_addressdata(in_place_id BIGINT, in_housenumber IN RETURNS setof addressline AS $$ DECLARE - place RECORD; + place addressdata_place; location RECORD; current_rank_address INTEGER; location_isaddress BOOLEAN; @@ -98,9 +110,9 @@ BEGIN -- first query osmline (interpolation lines) IF in_housenumber >= 0 THEN SELECT parent_place_id as place_id, country_code, - in_housenumber::text as housenumber, postcode, + in_housenumber as housenumber, postcode, 'place' as class, 'house' as type, - null::hstore as name, null::hstore as address, + null as name, null as address, ST_Centroid(linegeo) as centroid INTO place FROM location_property_osmline @@ -111,10 +123,10 @@ BEGIN --then query tiger data -- %NOTIGERDATA% IF 0 THEN IF place IS NULL AND in_housenumber >= 0 THEN - SELECT parent_place_id as place_id, 'us'::varchar(2) as country_code, - in_housenumber::text as housenumber, postcode, + SELECT parent_place_id as place_id, 'us' as country_code, + in_housenumber as housenumber, postcode, 'place' as class, 'house' as type, - null::hstore as name, null::hstore as address, + null as name, null as address, ST_Centroid(linegeo) as centroid INTO place FROM location_property_tiger @@ -125,10 +137,10 @@ BEGIN -- %NOAUXDATA% IF 0 THEN IF place IS NULL THEN - SELECT parent_place_id as place_id, 'us'::varchar(2) as country_code, + SELECT parent_place_id as place_id, 'us' as country_code, housenumber, postcode, 'place' as class, 'house' as type, - null::hstore as name, null::hstore as address, + null as name, null as address, centroid INTO place FROM location_property_aux @@ -141,8 +153,8 @@ BEGIN SELECT parent_place_id as place_id, country_code, null::text as housenumber, postcode, 'place' as class, 'postcode' as type, - null::hstore as name, null::hstore as address, - null::geometry as centroid + null as name, null as address, + null as centroid INTO place FROM location_postcode WHERE place_id = in_place_id; @@ -167,8 +179,8 @@ BEGIN select coalesce(linked_place_id, place_id) as place_id, country_code, housenumber, postcode, class, type, - null::hstore as name, address, - null::geometry as centroid + null as name, address, + null as centroid INTO place FROM placex where place_id = in_place_id; END IF; diff --git a/test/bdd/environment.py b/test/bdd/environment.py index f0658c33..8847011a 100644 --- a/test/bdd/environment.py +++ b/test/bdd/environment.py @@ -48,6 +48,7 @@ class NominatimEnvironment(object): self.keep_scenario_db = config['KEEP_TEST_DB'] self.code_coverage_path = config['PHPCOV'] self.code_coverage_id = 1 + self.test_env = None os.environ['NOMINATIM_SETTINGS'] = self.local_settings_file self.template_db_done = False @@ -72,19 +73,28 @@ class NominatimEnvironment(object): return fn def write_nominatim_config(self, dbname): - f = open(self.local_settings_file, 'w') - # https://secure.php.net/manual/en/ref.pdo-pgsql.connection.php - f.write("oDbStub = $this->getMockBuilder(\DB::class) diff --git a/test/php/Nominatim/ClassTypesTest.php b/test/php/Nominatim/ClassTypesTest.php index 1ba79bdb..10256954 100644 --- a/test/php/Nominatim/ClassTypesTest.php +++ b/test/php/Nominatim/ClassTypesTest.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/ClassTypes.php'); +require_once(CONST_LibDir.'/ClassTypes.php'); class ClassTypesTest extends \PHPUnit\Framework\TestCase { diff --git a/test/php/Nominatim/DBTest.php b/test/php/Nominatim/DBTest.php index 1991f6f1..8a3157a8 100644 --- a/test/php/Nominatim/DBTest.php +++ b/test/php/Nominatim/DBTest.php @@ -2,8 +2,8 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/lib.php'); -require_once(CONST_BasePath.'/lib/DB.php'); +require_once(CONST_LibDir.'/lib.php'); +require_once(CONST_LibDir.'/DB.php'); // subclassing so we can set the protected connection variable class NominatimSubClassedDB extends \Nominatim\DB diff --git a/test/php/Nominatim/DatabaseErrorTest.php b/test/php/Nominatim/DatabaseErrorTest.php index 7b461894..da156493 100644 --- a/test/php/Nominatim/DatabaseErrorTest.php +++ b/test/php/Nominatim/DatabaseErrorTest.php @@ -2,8 +2,8 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/init-website.php'); -require_once(CONST_BasePath.'/lib/DatabaseError.php'); +require_once(CONST_LibDir.'/init-website.php'); +require_once(CONST_LibDir.'/DatabaseError.php'); class DatabaseErrorTest extends \PHPUnit\Framework\TestCase { diff --git a/test/php/Nominatim/DebugTest.php b/test/php/Nominatim/DebugTest.php index 5d9525ac..09860914 100644 --- a/test/php/Nominatim/DebugTest.php +++ b/test/php/Nominatim/DebugTest.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/DebugHtml.php'); +require_once(CONST_LibDir.'/DebugHtml.php'); class DebugTest extends \PHPUnit\Framework\TestCase { diff --git a/test/php/Nominatim/LibTest.php b/test/php/Nominatim/LibTest.php index 28cd9af0..6e9038ee 100644 --- a/test/php/Nominatim/LibTest.php +++ b/test/php/Nominatim/LibTest.php @@ -2,8 +2,8 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/lib.php'); -require_once(CONST_BasePath.'/lib/ClassTypes.php'); +require_once(CONST_LibDir.'/lib.php'); +require_once(CONST_LibDir.'/ClassTypes.php'); class LibTest extends \PHPUnit\Framework\TestCase { diff --git a/test/php/Nominatim/OutputTest.php b/test/php/Nominatim/OutputTest.php index b243ba47..cbfebb7d 100644 --- a/test/php/Nominatim/OutputTest.php +++ b/test/php/Nominatim/OutputTest.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/output.php'); +require_once(CONST_LibDir.'/output.php'); class OutputTest extends \PHPUnit\Framework\TestCase { diff --git a/test/php/Nominatim/ParameterParserTest.php b/test/php/Nominatim/ParameterParserTest.php index 361fefc1..3b06e274 100644 --- a/test/php/Nominatim/ParameterParserTest.php +++ b/test/php/Nominatim/ParameterParserTest.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/ParameterParser.php'); +require_once(CONST_LibDir.'/ParameterParser.php'); function userError($sError) diff --git a/test/php/Nominatim/PhraseTest.php b/test/php/Nominatim/PhraseTest.php index ab031bb0..42166e34 100644 --- a/test/php/Nominatim/PhraseTest.php +++ b/test/php/Nominatim/PhraseTest.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/Phrase.php'); +require_once(CONST_LibDir.'/Phrase.php'); class TokensFullSet { diff --git a/test/php/Nominatim/SearchContextTest.php b/test/php/Nominatim/SearchContextTest.php index 2b575a16..1b346297 100644 --- a/test/php/Nominatim/SearchContextTest.php +++ b/test/php/Nominatim/SearchContextTest.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/SearchContext.php'); +require_once(CONST_LibDir.'/SearchContext.php'); class SearchContextTest extends \PHPUnit\Framework\TestCase { diff --git a/test/php/Nominatim/ShellTest.php b/test/php/Nominatim/ShellTest.php index d0222ee1..2d81b71d 100644 --- a/test/php/Nominatim/ShellTest.php +++ b/test/php/Nominatim/ShellTest.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/Shell.php'); +require_once(CONST_LibDir.'/Shell.php'); class ShellTest extends \PHPUnit\Framework\TestCase { diff --git a/test/php/Nominatim/StatusTest.php b/test/php/Nominatim/StatusTest.php index f45e6633..8cb8a703 100644 --- a/test/php/Nominatim/StatusTest.php +++ b/test/php/Nominatim/StatusTest.php @@ -2,8 +2,8 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/DB.php'); -require_once(CONST_BasePath.'/lib/Status.php'); +require_once(CONST_LibDir.'/DB.php'); +require_once(CONST_LibDir.'/Status.php'); class StatusTest extends \PHPUnit\Framework\TestCase diff --git a/test/php/Nominatim/TokenListTest.php b/test/php/Nominatim/TokenListTest.php index ca43aabb..3ef4d84d 100644 --- a/test/php/Nominatim/TokenListTest.php +++ b/test/php/Nominatim/TokenListTest.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/TokenList.php'); +require_once(CONST_LibDir.'/TokenList.php'); class TokenTest extends \PHPUnit\Framework\TestCase diff --git a/test/php/bootstrap.php b/test/php/bootstrap.php index d6968717..3a36db38 100644 --- a/test/php/bootstrap.php +++ b/test/php/bootstrap.php @@ -1,4 +1,6 @@ "\033[92m", @@ -26,6 +28,13 @@ function isReverseOnlyInstallation() return !$oDB->tableExists('search_name'); } +// Check (guess) if the setup.php included --drop +function isNoUpdateInstallation() +{ + global $oDB; + return $oDB->tableExists('placex') && !$oDB->tableExists('planet_osm_rels') ; +} + echo 'Checking database got created ... '; if ($oDB->checkConnection()) { @@ -35,7 +44,7 @@ if ($oDB->checkConnection()) { echo <<< END Hints: * Is the database server started? - * Check the CONST_Database_DSN variable in build/settings/local.php + * Check the NOMINATIM_DATABASE_DSN variable in your local .env * Try connecting to the database with the same settings END; @@ -61,27 +70,28 @@ END; exit(1); } -echo 'Checking place table ... '; -if ($oDB->tableExists('place')) { - $print_success(); -} else { - $print_fail(); - echo <<< END - * The import didn't finish. - Hints: - * Check the output of the utils/setup.php you ran. - Usually the osm2pgsql step failed. Check for errors related to - * the file you imported not containing any places - * harddrive full - * out of memory (RAM) - * osm2pgsql killed by other scripts, for consuming to much memory - -END; - exit(1); +if (!isNoUpdateInstallation()) { + echo 'Checking place table ... '; + if ($oDB->tableExists('place')) { + $print_success(); + } else { + $print_fail(); + echo <<< END + * The import didn't finish. + Hints: + * Check the output of the utils/setup.php you ran. + Usually the osm2pgsql step failed. Check for errors related to + * the file you imported not containing any places + * harddrive full + * out of memory (RAM) + * osm2pgsql killed by other scripts, for consuming to much memory + + END; + exit(1); + } } - echo 'Checking indexing status ... '; $iUnindexed = $oDB->getOne('SELECT count(*) FROM placex WHERE indexed_status > 0'); if ($iUnindexed == 0) { @@ -104,14 +114,11 @@ $aExpectedIndices = array( 'idx_place_addressline_address_place_id', 'idx_placex_rank_search', 'idx_placex_rank_address', - 'idx_placex_pendingsector', 'idx_placex_parent_place_id', 'idx_placex_geometry_reverse_lookuppolygon', 'idx_placex_geometry_reverse_placenode', - 'idx_location_area_country_place_id', 'idx_osmline_parent_place_id', 'idx_osmline_parent_osm_id', - 'idx_place_osm_unique', 'idx_postcode_id', 'idx_postcode_postcode' ); @@ -123,6 +130,13 @@ if (!isReverseOnlyInstallation()) { 'idx_search_name_centroid' )); } +if (!isNoUpdateInstallation()) { + $aExpectedIndices = array_merge($aExpectedIndices, array( + 'idx_placex_pendingsector', + 'idx_location_area_country_place_id', + 'idx_place_osm_unique', + )); +} foreach ($aExpectedIndices as $sExpectedIndex) { echo "Checking index $sExpectedIndex ... "; @@ -166,7 +180,7 @@ END; -if (CONST_Use_US_Tiger_Data) { +if (getSettingBool('USE_US_TIGER_DATA')) { echo 'Checking TIGER table exists ... '; if ($oDB->tableExists('location_property_tiger')) { $print_success(); diff --git a/utils/country_languages.php b/utils/country_languages.php index 63f6525c..1a7ea616 100644 --- a/utils/country_languages.php +++ b/utils/country_languages.php @@ -1,6 +1,6 @@ 1, 'country' => 4, diff --git a/utils/query.php b/utils/query.php index 6068c7c0..429b30ff 100644 --- a/utils/query.php +++ b/utils/query.php @@ -1,8 +1,8 @@ connect(); diff --git a/utils/setup.php b/utils/setup.php index 7f476d5c..713fe561 100644 --- a/utils/setup.php +++ b/utils/setup.php @@ -1,8 +1,8 @@ importTigerData(); + $sTigerPath = getSetting('TIGER_DATA_PATH'); + if (!$sTigerPath) { + $sTigerPath = CONST_DataDir.'/data/tiger'; + } + $oSetup->importTigerData($sTigerPath); } if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) { diff --git a/utils/specialphrases.php b/utils/specialphrases.php index 9e6c9d76..b1df6436 100644 --- a/utils/specialphrases.php +++ b/utils/specialphrases.php @@ -1,6 +1,6 @@ connect(); $fPostgresVersion = $oDB->getPostgresVersion(); -$aDSNInfo = Nominatim\DB::parseDSN(CONST_Database_DSN); +$aDSNInfo = Nominatim\DB::parseDSN(getSetting('DATABASE_DSN')); if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432; // cache memory to be used by osm2pgsql, should not be more than the available memory @@ -66,7 +71,7 @@ if ($iCacheMemory + 500 > getTotalMemoryMB()) { echo "WARNING: resetting cache memory to $iCacheMemory\n"; } -$oOsm2pgsqlCmd = (new \Nominatim\Shell(CONST_Osm2pgsql_Binary)) +$oOsm2pgsqlCmd = (new \Nominatim\Shell(getOsm2pgsqlBinary())) ->addParams('--hstore') ->addParams('--latlong') ->addParams('--append') @@ -76,7 +81,7 @@ $oOsm2pgsqlCmd = (new \Nominatim\Shell(CONST_Osm2pgsql_Binary)) ->addParams('--number-processes', 1) ->addParams('--cache', $iCacheMemory) ->addParams('--output', 'gazetteer') - ->addParams('--style', CONST_Import_Style) + ->addParams('--style', getImportStyle()) ->addParams('--database', $aDSNInfo['database']) ->addParams('--port', $aDSNInfo['port']); @@ -89,8 +94,8 @@ if (isset($aDSNInfo['username']) && $aDSNInfo['username']) { if (isset($aDSNInfo['password']) && $aDSNInfo['password']) { $oOsm2pgsqlCmd->addEnvPair('PGPASSWORD', $aDSNInfo['password']); } -if (!is_null(CONST_Osm2pgsql_Flatnode_File) && CONST_Osm2pgsql_Flatnode_File) { - $oOsm2pgsqlCmd->addParams('--flat-nodes', CONST_Osm2pgsql_Flatnode_File); +if (getSetting('FLATNODE_FILE')) { + $oOsm2pgsqlCmd->addParams('--flat-nodes', getSetting('FLATNODE_FILE')); } if ($fPostgresVersion >= 11.0) { $oOsm2pgsqlCmd->addEnvPair( @@ -100,7 +105,7 @@ if ($fPostgresVersion >= 11.0) { } -$oIndexCmd = (new \Nominatim\Shell(CONST_BasePath.'/nominatim/nominatim.py')) +$oIndexCmd = (new \Nominatim\Shell(CONST_DataDir.'/nominatim/nominatim.py')) ->addParams('--database', $aDSNInfo['database']) ->addParams('--port', $aDSNInfo['port']) ->addParams('--threads', $aResult['index-instances']); @@ -120,31 +125,34 @@ if (isset($aDSNInfo['password']) && $aDSNInfo['password']) { $oIndexCmd->addEnvPair('PGPASSWORD', $aDSNInfo['password']); } +$sPyosmiumBin = getSetting('PYOSMIUM_BINARY'); +$sBaseURL = getSetting('REPLICATION_URL'); + if ($aResult['init-updates']) { // sanity check that the replication URL is correct - $sBaseState = file_get_contents(CONST_Replication_Url.'/state.txt'); + $sBaseState = file_get_contents($sBaseURL.'/state.txt'); if ($sBaseState === false) { echo "\nCannot find state.txt file at the configured replication URL.\n"; echo "Does the URL point to a directory containing OSM update data?\n\n"; fail('replication URL not reachable.'); } // sanity check for pyosmium-get-changes - if (!CONST_Pyosmium_Binary) { - echo "\nCONST_Pyosmium_Binary not configured.\n"; + if (!$sPyosmiumBin) { + echo "\nNOMINATIM_PYOSMIUM_BINARY not configured.\n"; echo "You need to install pyosmium and set up the path to pyosmium-get-changes\n"; - echo "in your local settings file.\n\n"; - fail('CONST_Pyosmium_Binary not configured'); + echo "in your local .env file.\n\n"; + fail('NOMINATIM_PYOSMIUM_BINARY not configured'); } $aOutput = 0; - $oCMD = new \Nominatim\Shell(CONST_Pyosmium_Binary, '--help'); + $oCMD = new \Nominatim\Shell($sPyosmiumBin, '--help'); exec($oCMD->escapedCmd(), $aOutput, $iRet); if ($iRet != 0) { echo "Cannot execute pyosmium-get-changes.\n"; echo "Make sure you have pyosmium installed correctly\n"; - echo "and have set up CONST_Pyosmium_Binary to point to pyosmium-get-changes.\n"; + echo "and have set up NOMINATIM_PYOSMIUM_BINARY to point to pyosmium-get-changes.\n"; fail('pyosmium-get-changes not found or not usable'); } @@ -165,9 +173,9 @@ if ($aResult['init-updates']) { // get the appropriate state id $aOutput = 0; - $oCMD = (new \Nominatim\Shell(CONST_Pyosmium_Binary)) + $oCMD = (new \Nominatim\Shell($sPyosmiumBin)) ->addParams('--start-date', $sWindBack) - ->addParams('--server', CONST_Replication_Url); + ->addParams('--server', $sBaseURL); exec($oCMD->escapedCmd(), $aOutput, $iRet); if ($iRet != 0 || $aOutput[0] == 'None') { @@ -194,8 +202,8 @@ if ($aResult['check-for-updates']) { fail('Updates not set up. Please run ./utils/update.php --init-updates.'); } - $oCmd = (new \Nominatim\Shell(CONST_BasePath.'/utils/check_server_for_updates.py')) - ->addParams(CONST_Replication_Url) + $oCmd = (new \Nominatim\Shell(CONST_BinDir.'/check_server_for_updates.py')) + ->addParams($sBaseURL) ->addParams($aLastState['sequence_id']); $iRet = $oCmd->run(); @@ -224,11 +232,11 @@ if (isset($aResult['import-diff']) || isset($aResult['import-file'])) { if ($aResult['calculate-postcodes']) { info('Update postcodes centroids'); - $sTemplate = file_get_contents(CONST_BasePath.'/sql/update-postcodes.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/update-postcodes.sql'); runSQLScript($sTemplate, true, true); } -$sTemporaryFile = CONST_BasePath.'/data/osmosischange.osc'; +$sTemporaryFile = CONST_InstallDir.'/osmosischange.osc'; $bHaveDiff = false; $bUseOSMApi = isset($aResult['import-from-main-api']) && $aResult['import-from-main-api']; $sContentURL = ''; @@ -275,7 +283,7 @@ if ($bHaveDiff) { if ($aResult['recompute-word-counts']) { info('Recompute frequency of full-word search terms'); - $sTemplate = file_get_contents(CONST_BasePath.'/sql/words_from_search_name.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/words_from_search_name.sql'); runSQLScript($sTemplate, true, true); } @@ -292,8 +300,9 @@ if ($aResult['index']) { } if ($aResult['update-address-levels']) { - echo 'Updating address levels from '.CONST_Address_Level_Config.".\n"; - $oAlParser = new \Nominatim\Setup\AddressLevelParser(CONST_Address_Level_Config); + $sAddressLevelConfig = getSettingConfig('ADDRESS_LEVEL_CONFIG', 'address-levels.json'); + echo 'Updating address levels from '.$sAddressLevelConfig.".\n"; + $oAlParser = new \Nominatim\Setup\AddressLevelParser($sAddressLevelConfig); $oAlParser->createTable($oDB, 'address_levels'); } @@ -316,17 +325,17 @@ if ($aResult['recompute-importance']) { if ($aResult['import-osmosis'] || $aResult['import-osmosis-all']) { // - if (strpos(CONST_Replication_Url, 'download.geofabrik.de') !== false && CONST_Replication_Update_Interval < 86400) { + if (strpos($sBaseURL, 'download.geofabrik.de') !== false && getSetting('REPLICATION_UPDATE_INTERVAL') < 86400) { fail('Error: Update interval too low for download.geofabrik.de. ' . "Please check install documentation (https://nominatim.org/release-docs/latest/admin/Import-and-Update#setting-up-the-update-process)\n"); } - $sImportFile = CONST_InstallPath.'/osmosischange.osc'; + $sImportFile = CONST_InstallDir.'/osmosischange.osc'; - $oCMDDownload = (new \Nominatim\Shell(CONST_Pyosmium_Binary)) - ->addParams('--server', CONST_Replication_Url) + $oCMDDownload = (new \Nominatim\Shell($sPyosmiumBin)) + ->addParams('--server', $sBaseURL) ->addParams('--outfile', $sImportFile) - ->addParams('--size', CONST_Replication_Max_Diff_size); + ->addParams('--size', getSetting('REPLICATION_MAX_DIFF')); $oCMDImport = (clone $oOsm2pgsqlCmd)->addParams($sImportFile); @@ -346,7 +355,7 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all']) { if ($aLastState['indexed']) { // Sleep if the update interval has not yet been reached. - $fNextUpdate = $aLastState['unix_ts'] + CONST_Replication_Update_Interval; + $fNextUpdate = $aLastState['unix_ts'] + getSetting('REPLICATION_UPDATE_INTERVAL'); if ($fNextUpdate > $fStartTime) { $iSleepTime = $fNextUpdate - $fStartTime; echo "Waiting for next update for $iSleepTime sec."; @@ -367,8 +376,9 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all']) { exec($oCMD->escapedCmd(), $aOutput, $iResult); if ($iResult == 3) { - echo 'No new updates. Sleeping for '.CONST_Replication_Recheck_Interval." sec.\n"; - sleep(CONST_Replication_Recheck_Interval); + $sSleep = getSetting('REPLICATION_RECHECK_INTERVAL'); + echo 'No new updates. Sleeping for '.$sSleep." sec.\n"; + sleep($sSleep); } elseif ($iResult != 0) { echo 'ERROR: updates failed.'; exit($iResult); @@ -380,7 +390,7 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all']) { // get the newest object from the diff file $sBatchEnd = 0; $iRet = 0; - $oCMD = new \Nominatim\Shell(CONST_BasePath.'/utils/osm_file_date.py', $sImportFile); + $oCMD = new \Nominatim\Shell(CONST_BinDir.'/osm_file_date.py', $sImportFile); exec($oCMD->escapedCmd(), $sBatchEnd, $iRet); if ($iRet == 5) { echo "Diff file is empty. skipping import.\n"; diff --git a/utils/warm.php b/utils/warm.php index 5476eae0..0d8260f1 100644 --- a/utils/warm.php +++ b/utils/warm.php @@ -1,6 +1,11 @@ connect(); diff --git a/vagrant/Install-on-Centos-7.sh b/vagrant/Install-on-Centos-7.sh index c67aab7c..24b17663 100755 --- a/vagrant/Install-on-Centos-7.sh +++ b/vagrant/Install-on-Centos-7.sh @@ -6,6 +6,10 @@ # Installing the Required Software # ================================ # +# !!! caution +# These instructions are currently broken because they do not +# include installation of the required PHP library symfony-dotenv. +# # These instructions expect that you have a freshly installed CentOS version 7. # Make sure all packages are up-to-date by running: # @@ -189,10 +193,7 @@ fi #DOCS: # the name of your webserver user: #DOCS:```sh -tee settings/local.php << EOF -getSet('format', array('json'), 'json'); set_exception_handler_by_format($sOutputFormat); -$oDB = new Nominatim\DB(); +$oDB = new Nominatim\DB(CONST_Database_DSN); $oDB->connect(); $sSQL = 'select placex.place_id, country_code,'; diff --git a/website/details.php b/website/details.php index 77e74969..91440b54 100644 --- a/website/details.php +++ b/website/details.php @@ -1,9 +1,9 @@ getBool('hierarchy', false); $bGroupHierarchy = $oParams->getBool('group_hierarchy', false); $bIncludePolygonAsGeoJSON = $oParams->getBool('polygon_geojson', false); -$oDB = new Nominatim\DB(); +$oDB = new Nominatim\DB(CONST_Database_DSN); $oDB->connect(); $sLanguagePrefArraySQL = $oDB->getArraySQL($oDB->getDBQuotedList($aLangPrefOrder)); @@ -77,7 +77,7 @@ if ($sOsmType && $iOsmId > 0) { $aPointDetails['error_x'] = 0; $aPointDetails['error_y'] = 0; } - include(CONST_BasePath.'/lib/template/details-error-'.$sOutputFormat.'.php'); + include(CONST_LibDir.'/template/details-error-'.$sOutputFormat.'.php'); exit; } } @@ -247,4 +247,4 @@ if ($bIncludeKeywords) { logEnd($oDB, $hLog, 1); -include(CONST_BasePath.'/lib/template/details-'.$sOutputFormat.'.php'); +include(CONST_LibDir.'/template/details-'.$sOutputFormat.'.php'); diff --git a/website/lookup.php b/website/lookup.php index db2c01d6..737edc62 100644 --- a/website/lookup.php +++ b/website/lookup.php @@ -1,9 +1,9 @@ getPreferredLanguages(); -$oDB = new Nominatim\DB(); +$oDB = new Nominatim\DB(CONST_Database_DSN); $oDB->connect(); $hLog = logStart($oDB, 'place', $_SERVER['QUERY_STRING'], $aLangPrefOrder); @@ -84,4 +84,4 @@ $sMoreURL = ''; logEnd($oDB, $hLog, 1); $sOutputTemplate = ($sOutputFormat == 'jsonv2') ? 'json' : $sOutputFormat; -include(CONST_BasePath.'/lib/template/search-'.$sOutputTemplate.'.php'); +include(CONST_LibDir.'/template/search-'.$sOutputTemplate.'.php'); diff --git a/website/polygons.php b/website/polygons.php index 9c657a1d..88b48ae8 100644 --- a/website/polygons.php +++ b/website/polygons.php @@ -1,8 +1,8 @@ getInt('days', false); $bReduced = $oParams->getBool('reduced', false); $sClass = $oParams->getString('class', false); -$oDB = new Nominatim\DB(); +$oDB = new Nominatim\DB(CONST_Database_DSN); $oDB->connect(); $iTotalBroken = (int) $oDB->getOne('SELECT count(*) FROM import_polygon_error'); diff --git a/website/reverse.php b/website/reverse.php index 640ea2ab..553c2692 100644 --- a/website/reverse.php +++ b/website/reverse.php @@ -1,10 +1,10 @@ getPreferredLanguages(); -$oDB = new Nominatim\DB(); +$oDB = new Nominatim\DB(CONST_Database_DSN); $oDB->connect(); $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder); @@ -84,4 +84,4 @@ if ($sOutputFormat == 'geocodejson') { } $sOutputTemplate = ($sOutputFormat == 'jsonv2') ? 'json' : $sOutputFormat; -include(CONST_BasePath.'/lib/template/address-'.$sOutputTemplate.'.php'); +include(CONST_LibDir.'/template/address-'.$sOutputTemplate.'.php'); diff --git a/website/search.php b/website/search.php index 43c9fd01..619dec6d 100644 --- a/website/search.php +++ b/website/search.php @@ -1,12 +1,12 @@ connect(); $oParams = new Nominatim\ParameterParser(); @@ -15,15 +15,6 @@ $oGeocode = new Nominatim\Geocode($oDB); $aLangPrefOrder = $oParams->getPreferredLanguages(); $oGeocode->setLanguagePreference($aLangPrefOrder); -if (CONST_Search_ReversePlanForAll - || isset($aLangPrefOrder['name:de']) - || isset($aLangPrefOrder['name:ru']) - || isset($aLangPrefOrder['name:ja']) - || isset($aLangPrefOrder['name:pl']) -) { - $oGeocode->setReverseInPlan(true); -} - // Format for output $sOutputFormat = $oParams->getSet('format', array('xml', 'json', 'jsonv2', 'geojson', 'geocodejson'), 'jsonv2'); set_exception_handler_by_format($sOutputFormat); @@ -41,7 +32,7 @@ if (CONST_Search_BatchMode && isset($_GET['batch'])) { $aSearchResults = $oBatchGeocode->lookup(); $aBatchResults[] = $aSearchResults; } - include(CONST_BasePath.'/lib/template/search-batch-json.php'); + include(CONST_LibDir.'/template/search-batch-json.php'); exit; } @@ -89,4 +80,4 @@ if (isset($_SERVER['REQUEST_SCHEME']) if (CONST_Debug) exit; $sOutputTemplate = ($sOutputFormat == 'jsonv2') ? 'json' : $sOutputFormat; -include(CONST_BasePath.'/lib/template/search-'.$sOutputTemplate.'.php'); +include(CONST_LibDir.'/template/search-'.$sOutputTemplate.'.php'); diff --git a/website/status.php b/website/status.php index 0d483544..9f030fb3 100644 --- a/website/status.php +++ b/website/status.php @@ -1,13 +1,13 @@ getSet('format', array('text', 'json'), 'text'); -$oDB = new Nominatim\DB(); +$oDB = new Nominatim\DB(CONST_Database_DSN); if ($sOutputFormat == 'json') { header('content-type: application/json; charset=UTF-8');