From: Sarah Hoffmann Date: Thu, 1 Mar 2018 22:48:45 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/master' X-Git-Tag: deploy~338 X-Git-Url: https://git.openstreetmap.org/nominatim.git/commitdiff_plain/12168e3ca9421ab1d0195507919c26ce029ce155?hp=87f68937540b406f35feaa3435f951e7dc6d70ec Merge remote-tracking branch 'upstream/master' --- diff --git a/.travis.yml b/.travis.yml index 5efc9f08..c67f155e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ script: - if [[ $TEST_SUITE == "monaco" ]]; then ./utils/specialphrases.php --wiki-import | psql -d test_api_nominatim >/dev/null; fi - cd $TRAVIS_BUILD_DIR/test/php - if [[ $TEST_SUITE == "tests" ]]; then phpunit ./ ; fi - - if [[ $TEST_SUITE == "tests" ]]; then phpcs --report-width=120 */**.php ; fi + - if [[ $TEST_SUITE == "tests" ]]; then phpcs --report-width=120 . ; fi - cd $TRAVIS_BUILD_DIR/test/bdd - # behave --format=progress3 api - if [[ $TEST_SUITE == "tests" ]]; then behave --format=progress3 db ; fi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a00d0ed3..dc5be190 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -82,7 +82,7 @@ are in process of consolodating the style. The following rules apply: The coding style is enforced with PHPCS and can be tested with: ``` - phpcs --report-width=120 --colors */**.php + phpcs --report-width=120 --colors . ``` ## Testing diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index e8596e49..d2fe03d0 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -8,6 +8,7 @@ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/appendix) ADD_CUSTOM_TARGET(doc COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/admin ${CMAKE_CURRENT_BINARY_DIR}/admin + COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/develop ${CMAKE_CURRENT_BINARY_DIR}/develop COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/index.md ${CMAKE_CURRENT_BINARY_DIR}/index.md COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bash2md.sh ${PROJECT_SOURCE_DIR}/vagrant/Install-on-Centos-7.sh ${CMAKE_CURRENT_BINARY_DIR}/appendix/Install-on-Centos-7.md COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bash2md.sh ${PROJECT_SOURCE_DIR}/vagrant/Install-on-Ubuntu-16.sh ${CMAKE_CURRENT_BINARY_DIR}/appendix/Install-on-Ubuntu-16.md diff --git a/docs/admin/Faq.md b/docs/admin/Faq.md index 470e936c..a1624d26 100644 --- a/docs/admin/Faq.md +++ b/docs/admin/Faq.md @@ -3,7 +3,7 @@ ### Can I import only a few countries and also keep them up to date? You should use the extracts and updates from https://download.geofabrik.de. -For the intial import, download the countries you need and merge them. +For the initial import, download the countries you need and merge them. See [OSM Help](https://help.openstreetmap.org/questions/48843/merging-two-or-more-geographical-areas-to-import-two-or-more-osm-files-in-nominatim) for examples how to do that. Use the resulting single osm file when running `setup.php`. diff --git a/docs/admin/Installation.md b/docs/admin/Installation.md index ce7fb412..67c4fe3c 100644 --- a/docs/admin/Installation.md +++ b/docs/admin/Installation.md @@ -8,6 +8,13 @@ the following operating systems: These OS-specific instructions can also be found in executable form in the `vagrant/` directory. +Users have created instructions for other frameworks. We haven't tested those +and can't offer support. + + * [Docker](https://github.com/mediagis/nominatim-docker) + * [Docker on Kubernetes](https://github.com/peter-evans/nominatim-k8s) + * [Ansible](https://github.com/synthesio/infra-ansible-nominatim) + # Prerequisites ## Software diff --git a/docs/develop/overview.md b/docs/develop/overview.md new file mode 100644 index 00000000..179eeb0b --- /dev/null +++ b/docs/develop/overview.md @@ -0,0 +1,24 @@ +# Basic Architecture + +Nominatim provides geocoding based on OpenStreetMap data. It uses a Postgresql +database as a backend for storing the data. + +There are three basic parts to Nominatim's architecture: the data import, +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 +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/pqSQL via database triggers +and can be found in the file `sql/functions.sql`. + +The __search frontend__ implements the actual API. It takes queries for +search and reverse geocoding queries from the user, looks up the data and +returns the results in the requested format. This part is written in PHP +and can be found in the `lib/` and `website/` directories. diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index d647dd87..b0aee5d0 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -10,6 +10,8 @@ pages: - 'Importing and Updating' : 'admin/Import-and-Update.md' - 'Migration from older Versions' : 'admin/Migration.md' - 'Troubleshooting' : 'admin/Faq.md' + - 'Developers Guide': + - 'Overview' : 'develop/overview.md' - 'Appendix': - 'Installation on CentOS 7' : 'appendix/Install-on-Centos-7.md' - 'Installation on Ubuntu 16' : 'appendix/Install-on-Ubuntu-16.md' diff --git a/lib/SearchContext.php b/lib/SearchContext.php index 3e722d87..b0ff38d8 100644 --- a/lib/SearchContext.php +++ b/lib/SearchContext.php @@ -47,7 +47,7 @@ class SearchContext /** * Get radius around reference point. * - * @return float Search radius around refernce point. + * @return float Search radius around reference point. */ public function nearRadius() { diff --git a/lib/SearchDescription.php b/lib/SearchDescription.php index 6b66e5a5..a1910231 100644 --- a/lib/SearchDescription.php +++ b/lib/SearchDescription.php @@ -58,7 +58,7 @@ class SearchDescription /** * Get current search rank. * - * The higher the search rank the lower the likelyhood that the + * The higher the search rank the lower the likelihood that the * search is a correct interpretation of the search query. * * @return integer Search rank. @@ -289,10 +289,14 @@ class SearchDescription $this->aFullNameAddress[$iWordID] = $iWordID; } } else { - $oSearch = clone $this; - $oSearch->iSearchRank++; - $oSearch->aName = array($iWordID => $iWordID); - $aNewSearches[] = $oSearch; + // in structured search only the first phrase can be the + // designated name + if ($sPhraseType == '' || $bFirstPhrase) { + $oSearch = clone $this; + $oSearch->iSearchRank++; + $oSearch->aName = array($iWordID => $iWordID); + $aNewSearches[] = $oSearch; + } } } diff --git a/lib/template/address-json.php b/lib/template/address-json.php index 93abb601..cea87745 100644 --- a/lib/template/address-json.php +++ b/lib/template/address-json.php @@ -2,20 +2,15 @@ $aFilteredPlaces = array(); -if (!sizeof($aPlace)) -{ +if (!sizeof($aPlace)) { if (isset($sError)) $aFilteredPlaces['error'] = $sError; - else - $aFilteredPlaces['error'] = 'Unable to geocode'; -} -else -{ + else $aFilteredPlaces['error'] = 'Unable to geocode'; +} else { if (isset($aPlace['place_id'])) $aFilteredPlaces['place_id'] = $aPlace['place_id']; - $aFilteredPlaces['licence'] = "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright"; + $aFilteredPlaces['licence'] = 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright'; $sOSMType = formatOSMType($aPlace['osm_type']); - if ($sOSMType) - { + if ($sOSMType) { $aFilteredPlaces['osm_type'] = $sOSMType; $aFilteredPlaces['osm_id'] = $aPlace['osm_id']; } @@ -26,31 +21,25 @@ else if (isset($aPlace['sExtraTags'])) $aFilteredPlaces['extratags'] = $aPlace['sExtraTags']; if (isset($aPlace['sNameDetails'])) $aFilteredPlaces['namedetails'] = $aPlace['sNameDetails']; - if (isset($aPlace['aBoundingBox'])) - { + if (isset($aPlace['aBoundingBox'])) { $aFilteredPlaces['boundingbox'] = $aPlace['aBoundingBox']; } - if (isset($aPlace['asgeojson'])) - { + if (isset($aPlace['asgeojson'])) { $aFilteredPlaces['geojson'] = json_decode($aPlace['asgeojson']); } - if (isset($aPlace['assvg'])) - { + if (isset($aPlace['assvg'])) { $aFilteredPlaces['svg'] = $aPlace['assvg']; } - if (isset($aPlace['astext'])) - { + if (isset($aPlace['astext'])) { $aFilteredPlaces['geotext'] = $aPlace['astext']; } - if (isset($aPlace['askml'])) - { + if (isset($aPlace['askml'])) { $aFilteredPlaces['geokml'] = $aPlace['askml']; } } javascript_renderData($aFilteredPlaces); - diff --git a/lib/template/address-jsonv2.php b/lib/template/address-jsonv2.php index 229303be..399c978f 100644 --- a/lib/template/address-jsonv2.php +++ b/lib/template/address-jsonv2.php @@ -2,20 +2,15 @@ $aFilteredPlaces = array(); -if (!sizeof($aPlace)) -{ +if (!sizeof($aPlace)) { if (isset($sError)) $aFilteredPlaces['error'] = $sError; - else - $aFilteredPlaces['error'] = 'Unable to geocode'; -} -else -{ + else $aFilteredPlaces['error'] = 'Unable to geocode'; +} else { if ($aPlace['place_id']) $aFilteredPlaces['place_id'] = $aPlace['place_id']; - $aFilteredPlaces['licence'] = "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright"; + $aFilteredPlaces['licence'] = 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright'; $sOSMType = formatOSMType($aPlace['osm_type']); - if ($sOSMType) - { + if ($sOSMType) { $aFilteredPlaces['osm_type'] = $sOSMType; $aFilteredPlaces['osm_id'] = $aPlace['osm_id']; } @@ -38,31 +33,25 @@ else if (isset($aPlace['sExtraTags'])) $aFilteredPlaces['extratags'] = $aPlace['sExtraTags']; if (isset($aPlace['sNameDetails'])) $aFilteredPlaces['namedetails'] = $aPlace['sNameDetails']; - if (isset($aPlace['aBoundingBox'])) - { + if (isset($aPlace['aBoundingBox'])) { $aFilteredPlaces['boundingbox'] = $aPlace['aBoundingBox']; } - if (isset($aPlace['asgeojson'])) - { + if (isset($aPlace['asgeojson'])) { $aFilteredPlaces['geojson'] = json_decode($aPlace['asgeojson']); } - if (isset($aPlace['assvg'])) - { + if (isset($aPlace['assvg'])) { $aFilteredPlaces['svg'] = $aPlace['assvg']; } - if (isset($aPlace['astext'])) - { + if (isset($aPlace['astext'])) { $aFilteredPlaces['geotext'] = $aPlace['astext']; } - if (isset($aPlace['askml'])) - { + if (isset($aPlace['askml'])) { $aFilteredPlaces['geokml'] = $aPlace['askml']; } - } javascript_renderData($aFilteredPlaces); diff --git a/lib/template/address-xml.php b/lib/template/address-xml.php index d3db2edd..6183b284 100644 --- a/lib/template/address-xml.php +++ b/lib/template/address-xml.php @@ -1,103 +1,87 @@ \n"; -echo "\n"; -if (!sizeof($aPlace)) -{ +if (!sizeof($aPlace)) { if (isset($sError)) echo "$sError"; - else - echo "Unable to geocode"; -} -else -{ - echo "Unable to geocode'; +} else { + echo '".htmlspecialchars($aPlace['langaddress']).""; + echo '>'.htmlspecialchars($aPlace['langaddress']).''; - if (isset($aPlace['aAddress'])) - { - echo ""; - foreach($aPlace['aAddress'] as $sKey => $sValue) - { - $sKey = str_replace(' ','_',$sKey); + if (isset($aPlace['aAddress'])) { + echo ''; + foreach ($aPlace['aAddress'] as $sKey => $sValue) { + $sKey = str_replace(' ', '_', $sKey); echo "<$sKey>"; echo htmlspecialchars($sValue); echo ""; } - echo ""; + echo ''; } - if (isset($aPlace['sExtraTags'])) - { - echo ""; - foreach ($aPlace['sExtraTags'] as $sKey => $sValue) - { + if (isset($aPlace['sExtraTags'])) { + echo ''; + foreach ($aPlace['sExtraTags'] as $sKey => $sValue) { echo ''; } - echo ""; + echo ''; } - if (isset($aPlace['sNameDetails'])) - { - echo ""; - foreach ($aPlace['sNameDetails'] as $sKey => $sValue) - { + if (isset($aPlace['sNameDetails'])) { + echo ''; + foreach ($aPlace['sNameDetails'] as $sKey => $sValue) { echo ''; echo htmlspecialchars($sValue); - echo ""; + echo ''; } - echo ""; + echo ''; } - if (isset($aPlace['askml'])) - { + if (isset($aPlace['askml'])) { echo "\n"; echo $aPlace['askml']; - echo ""; + echo ''; } - } -echo ""; +echo ''; diff --git a/lib/template/search-batch-json.php b/lib/template/search-batch-json.php index a3ced45b..09ea48b6 100644 --- a/lib/template/search-batch-json.php +++ b/lib/template/search-batch-json.php @@ -1,42 +1,37 @@ $aPointDetails) - { + foreach ($aSearchResults as $iResNum => $aPointDetails) { $aPlace = array( - 'place_id'=>$aPointDetails['place_id'], - ); + 'place_id'=>$aPointDetails['place_id'], + ); $sOSMType = formatOSMType($aPointDetails['osm_type']); - if ($sOSMType) - { + if ($sOSMType) { $aPlace['osm_type'] = $sOSMType; $aPlace['osm_id'] = $aPointDetails['osm_id']; } - if (isset($aPointDetails['aBoundingBox'])) - { + if (isset($aPointDetails['aBoundingBox'])) { $aPlace['boundingbox'] = array( - $aPointDetails['aBoundingBox'][0], - $aPointDetails['aBoundingBox'][1], - $aPointDetails['aBoundingBox'][2], - $aPointDetails['aBoundingBox'][3]); + $aPointDetails['aBoundingBox'][0], + $aPointDetails['aBoundingBox'][1], + $aPointDetails['aBoundingBox'][2], + $aPointDetails['aBoundingBox'][3] + ); - if (isset($aPointDetails['aPolyPoints']) && $bShowPolygons) - { + if (isset($aPointDetails['aPolyPoints']) && $bShowPolygons) { $aPlace['polygonpoints'] = $aPointDetails['aPolyPoints']; } } - if (isset($aPointDetails['zoom'])) - { + if (isset($aPointDetails['zoom'])) { $aPlace['zoom'] = $aPointDetails['zoom']; } @@ -50,33 +45,27 @@ foreach($aBatchResults as $aSearchResults) $aPlace['importance'] = $aPointDetails['importance']; - if (isset($aPointDetails['icon'])) - { + if (isset($aPointDetails['icon'])) { $aPlace['icon'] = $aPointDetails['icon']; } - if (isset($aPointDetails['address']) && sizeof($aPointDetails['address'])>0) - { + if (isset($aPointDetails['address']) && sizeof($aPointDetails['address'])>0) { $aPlace['address'] = $aPointDetails['address']; } - if (isset($aPointDetails['asgeojson'])) - { + if (isset($aPointDetails['asgeojson'])) { $aPlace['geojson'] = json_decode($aPointDetails['asgeojson']); } - if (isset($aPointDetails['assvg'])) - { + if (isset($aPointDetails['assvg'])) { $aPlace['svg'] = $aPointDetails['assvg']; } - if (isset($aPointDetails['astext'])) - { + if (isset($aPointDetails['astext'])) { $aPlace['geotext'] = $aPointDetails['astext']; } - if (isset($aPointDetails['askml'])) - { + if (isset($aPointDetails['askml'])) { $aPlace['geokml'] = $aPointDetails['askml']; } diff --git a/lib/template/search-json.php b/lib/template/search-json.php index 846d654c..b997f6d9 100644 --- a/lib/template/search-json.php +++ b/lib/template/search-json.php @@ -1,33 +1,28 @@ $aPointDetails) -{ +foreach ($aSearchResults as $iResNum => $aPointDetails) { $aPlace = array( - 'place_id'=>$aPointDetails['place_id'], - 'licence'=>"Data © OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright", - ); + 'place_id'=>$aPointDetails['place_id'], + 'licence'=>'Data © OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright', + ); $sOSMType = formatOSMType($aPointDetails['osm_type']); - if ($sOSMType) - { + if ($sOSMType) { $aPlace['osm_type'] = $sOSMType; $aPlace['osm_id'] = $aPointDetails['osm_id']; } - if (isset($aPointDetails['aBoundingBox'])) - { + if (isset($aPointDetails['aBoundingBox'])) { $aPlace['boundingbox'] = $aPointDetails['aBoundingBox']; - if (isset($aPointDetails['aPolyPoints'])) - { + if (isset($aPointDetails['aPolyPoints'])) { $aPlace['polygonpoints'] = $aPointDetails['aPolyPoints']; } } - if (isset($aPointDetails['zoom'])) - { + if (isset($aPointDetails['zoom'])) { $aPlace['zoom'] = $aPointDetails['zoom']; } @@ -40,33 +35,27 @@ foreach($aSearchResults as $iResNum => $aPointDetails) $aPlace['importance'] = $aPointDetails['importance']; - if (isset($aPointDetails['icon']) && $aPointDetails['icon']) - { + if (isset($aPointDetails['icon']) && $aPointDetails['icon']) { $aPlace['icon'] = $aPointDetails['icon']; } - if (isset($aPointDetails['address'])) - { + if (isset($aPointDetails['address'])) { $aPlace['address'] = $aPointDetails['address']; } - if (isset($aPointDetails['asgeojson'])) - { + if (isset($aPointDetails['asgeojson'])) { $aPlace['geojson'] = json_decode($aPointDetails['asgeojson']); } - if (isset($aPointDetails['assvg'])) - { + if (isset($aPointDetails['assvg'])) { $aPlace['svg'] = $aPointDetails['assvg']; } - if (isset($aPointDetails['astext'])) - { + if (isset($aPointDetails['astext'])) { $aPlace['geotext'] = $aPointDetails['astext']; } - if (isset($aPointDetails['askml'])) - { + if (isset($aPointDetails['askml'])) { $aPlace['geokml'] = $aPointDetails['askml']; } diff --git a/lib/template/search-jsonv2.php b/lib/template/search-jsonv2.php index 5d2802af..76103304 100644 --- a/lib/template/search-jsonv2.php +++ b/lib/template/search-jsonv2.php @@ -1,32 +1,27 @@ $aPointDetails) -{ +foreach ($aSearchResults as $iResNum => $aPointDetails) { $aPlace = array( - 'place_id'=>$aPointDetails['place_id'], - 'licence'=>"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", - ); + 'place_id'=>$aPointDetails['place_id'], + 'licence'=>'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', + ); $sOSMType = formatOSMType($aPointDetails['osm_type']); - if ($sOSMType) - { + if ($sOSMType) { $aPlace['osm_type'] = $sOSMType; $aPlace['osm_id'] = $aPointDetails['osm_id']; } - if (isset($aPointDetails['aBoundingBox'])) - { + if (isset($aPointDetails['aBoundingBox'])) { $aPlace['boundingbox'] = $aPointDetails['aBoundingBox']; - if (isset($aPointDetails['aPolyPoints'])) - { + if (isset($aPointDetails['aPolyPoints'])) { $aPlace['polygonpoints'] = $aPointDetails['aPolyPoints']; } } - if (isset($aPointDetails['zoom'])) - { + if (isset($aPointDetails['zoom'])) { $aPlace['zoom'] = $aPointDetails['zoom']; } @@ -40,33 +35,27 @@ foreach($aSearchResults as $iResNum => $aPointDetails) $aPlace['importance'] = $aPointDetails['importance']; - if (isset($aPointDetails['icon'])) - { + if (isset($aPointDetails['icon'])) { $aPlace['icon'] = $aPointDetails['icon']; } - if (isset($aPointDetails['address']) && sizeof($aPointDetails['address'])>0) - { + if (isset($aPointDetails['address']) && sizeof($aPointDetails['address'])>0) { $aPlace['address'] = $aPointDetails['address']; } - if (isset($aPointDetails['asgeojson'])) - { + if (isset($aPointDetails['asgeojson'])) { $aPlace['geojson'] = json_decode($aPointDetails['asgeojson']); } - if (isset($aPointDetails['assvg'])) - { + if (isset($aPointDetails['assvg'])) { $aPlace['svg'] = $aPointDetails['assvg']; } - if (isset($aPointDetails['astext'])) - { + if (isset($aPointDetails['astext'])) { $aPlace['geotext'] = $aPointDetails['astext']; } - if (isset($aPointDetails['askml'])) - { + if (isset($aPointDetails['askml'])) { $aPlace['geokml'] = $aPointDetails['askml']; } diff --git a/lib/template/search-xml.php b/lib/template/search-xml.php index 80414fce..94bb7ec9 100644 --- a/lib/template/search-xml.php +++ b/lib/template/search-xml.php @@ -1,72 +1,63 @@ \n"; -echo "<"; +echo '<'; echo (isset($sXmlRootTag)?$sXmlRootTag:'searchresults'); echo " timestamp='".date(DATE_RFC822)."'"; echo " attribution='Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright'"; echo " querystring='".htmlspecialchars($sQuery, ENT_QUOTES)."'"; if (isset($aMoreParams['viewbox'])) echo " viewbox='".htmlspecialchars($aMoreParams['viewbox'], ENT_QUOTES)."'"; echo " polygon='".(isset($aMoreParams['polygon'])?'true':'false')."'"; -if (isset($aMoreParams['exclude_place_ids'])) -{ +if (isset($aMoreParams['exclude_place_ids'])) { echo " exclude_place_ids='".htmlspecialchars($aMoreParams['exclude_place_ids'])."'"; } echo " more_url='".htmlspecialchars($sMoreURL)."'"; echo ">\n"; -foreach($aSearchResults as $iResNum => $aResult) -{ +foreach ($aSearchResults as $iResNum => $aResult) { echo " $aResult) echo " class='".htmlspecialchars($aResult['class'])."'"; echo " type='".htmlspecialchars($aResult['type'], ENT_QUOTES)."'"; echo " importance='".htmlspecialchars($aResult['importance'])."'"; - if (isset($aResult['icon']) && $aResult['icon']) - { + if (isset($aResult['icon']) && $aResult['icon']) { echo " icon='".htmlspecialchars($aResult['icon'], ENT_QUOTES)."'"; } $bHasDelim = false; - if (isset($aResult['askml'])) - { - if (!$bHasDelim) - { + if (isset($aResult['askml'])) { + if (!$bHasDelim) { $bHasDelim = true; - echo ">"; + echo '>'; } echo "\n"; echo $aResult['askml']; - echo ""; + echo ''; } - if (isset($aResult['sExtraTags'])) - { - if (!$bHasDelim) - { + if (isset($aResult['sExtraTags'])) { + if (!$bHasDelim) { $bHasDelim = true; - echo ">"; + echo '>'; } echo "\n"; - foreach ($aResult['sExtraTags'] as $sKey => $sValue) - { + foreach ($aResult['sExtraTags'] as $sKey => $sValue) { echo ''; } - echo ""; + echo ''; } - if (isset($aResult['sNameDetails'])) - { - if (!$bHasDelim) - { + if (isset($aResult['sNameDetails'])) { + if (!$bHasDelim) { $bHasDelim = true; - echo ">"; + echo '>'; } echo "\n"; - foreach ($aResult['sNameDetails'] as $sKey => $sValue) - { + foreach ($aResult['sNameDetails'] as $sKey => $sValue) { echo ''; echo htmlspecialchars($sValue); - echo ""; + echo ''; } - echo ""; + echo ''; } - if (isset($aResult['address'])) - { - if (!$bHasDelim) - { + if (isset($aResult['address'])) { + if (!$bHasDelim) { $bHasDelim = true; - echo ">"; + echo '>'; } echo "\n"; - foreach($aResult['address'] as $sKey => $sValue) - { - $sKey = str_replace(' ','_',$sKey); + foreach ($aResult['address'] as $sKey => $sValue) { + $sKey = str_replace(' ', '_', $sKey); echo "<$sKey>"; echo htmlspecialchars($sValue); echo ""; } } - if ($bHasDelim) - { - echo ""; - } - else - { - echo "/>"; + if ($bHasDelim) { + echo ''; + } else { + echo '/>'; } } -echo ""; +echo ''; diff --git a/module/nominatim.c b/module/nominatim.c index 75238e22..73bf16c8 100644 --- a/module/nominatim.c +++ b/module/nominatim.c @@ -157,17 +157,18 @@ transliteration( PG_FUNCTION_ARGS ) PG_RETURN_TEXT_P(result); } +// Set isspace=1 if the replacement _only_ adds a space before the search string. I.e. to == " " + from void str_replace(char* buffer, int* len, int* changes, char* from, int fromlen, char* to, int tolen, int isspace) { char *p; - // Search string is too long to be pressent + // Search string is too long to be present if (fromlen > *len) return; p = strstr(buffer, from); while(p) { - if (!isspace || *(p-1) != ' ') + if (!isspace || (p > buffer && *(p-1) != ' ')) { (*changes)++; if (tolen != fromlen) memmove(p+tolen, p+fromlen, *len-(p-buffer)+1); @@ -230,7 +231,7 @@ gettokenstring( PG_FUNCTION_ARGS ) sourcedata = (unsigned char *)VARDATA(source); sourcedatalength = VARSIZE(source) - VARHDRSZ; - // Buffer for doing the replace in - string could get slightly longer (double is mastive overkill) + // Buffer for doing the replace in - string could get slightly longer (double is massive overkill) buffer = (char *)palloc((sourcedatalength*2)*sizeof(char)); memcpy(buffer+1, sourcedata, sourcedatalength); buffer[0] = 32; diff --git a/phpcs.xml b/phpcs.xml index 8f92f7c9..a48b5c3e 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -8,6 +8,12 @@ + ./lib/template/*html* + ./lib/template/includes/ + ./module/ + ./website/css + ./website/js + @@ -80,19 +86,6 @@ INDENTATION, SPACING ************************************************************** --> - - - 0 - - - - - 0 - - - 0 - - 0 diff --git a/test/bdd/db/import/parenting.feature b/test/bdd/db/import/parenting.feature index 401a58f1..87467fd2 100644 --- a/test/bdd/db/import/parenting.feature +++ b/test/bdd/db/import/parenting.feature @@ -20,12 +20,12 @@ Feature: Parenting of objects | N2 | W1 | When searching for "4 galoo" Then results contain - | ID | osm_type | osm_id | langaddress - | 0 | N | 1 | 4, galoo, 12345 + | ID | osm_type | osm_id | langaddress | + | 0 | N | 1 | 4, galoo, 12345 | When searching for "5 galoo" Then results contain - | ID | osm_type | osm_id | langaddress - | 0 | N | 2 | 5, galoo, 99999 + | ID | osm_type | osm_id | langaddress | + | 0 | N | 2 | 5, galoo, 99999 | Scenario: Address without tags, closest street Given the scene roads-with-pois diff --git a/test/bdd/db/import/postcodes.feature b/test/bdd/db/import/postcodes.feature index be469fe6..4c49dc5b 100644 --- a/test/bdd/db/import/postcodes.feature +++ b/test/bdd/db/import/postcodes.feature @@ -2,7 +2,7 @@ Feature: Import of postcodes Tests for postcode estimation - Scenario: Postcodes on the object are prefered over those on the address + Scenario: Postcodes on the object are preferred over those on the address Given the scene admin-areas And the named places | osm | class | type | admin | addr+postcode | geometry | diff --git a/test/bdd/osm2pgsql/update/relation.feature b/test/bdd/osm2pgsql/update/relation.feature index 83ce9129..fd8b83e3 100644 --- a/test/bdd/osm2pgsql/update/relation.feature +++ b/test/bdd/osm2pgsql/update/relation.feature @@ -11,11 +11,11 @@ Feature: Update of relations by osm2pgsql n202 x0.0001 y0.0001 n203 x0.0001 y0 w2 Tref=45' Nn200,n201,n202,n203,n200 - r1 Ttype=multipolygon,tourism=hotel,name=XZ' Mw2@ + r1 Ttype=multipolygon,tourism=hotel,name=XZ Mw2@ """ Then place contains - | object | class | type | name - | R1 | tourism | hotel | 'name' : 'XZ' + | object | class | type | name | + | R1 | tourism | hotel | 'name' : 'XZ' | When updating osm data """ r1 Ttype=multipolygon,tourism=hotel,name=XZ Mn1@ @@ -34,16 +34,16 @@ Feature: Update of relations by osm2pgsql r1 Ttype=multipolygon,tourism=hotel,name=XZ Mw2@ """ Then place contains - | object | class | type | name - | R1 | tourism | hotel | 'name' : 'XZ' + | object | class | type | name | + | R1 | tourism | hotel | 'name' : 'XZ' | When updating osm data """ r1 Ttype=multipolygon,amenity=prison,name=XZ Mw2@ """ Then place has no entry for R1:tourism And place contains - | object | class | type | name - | R1 | amenity | prison | 'name' : 'XZ' + | object | class | type | name | + | R1 | amenity | prison | 'name' : 'XZ' | Scenario: Change name of a relation When loading osm data @@ -56,15 +56,15 @@ Feature: Update of relations by osm2pgsql r1 Ttype=multipolygon,tourism=hotel,name=AB Mw2@ """ Then place contains - | object | class | type | name - | R1 | tourism | hotel | 'name' : 'AB' + | object | class | type | name | + | R1 | tourism | hotel | 'name' : 'AB' | When updating osm data """ r1 Ttype=multipolygon,tourism=hotel,name=XY Mw2@ """ Then place contains - | object | class | type | name - | R1 | tourism | hotel | 'name' : 'XZ' + | object | class | type | name | + | R1 | tourism | hotel | 'name' : 'XY' | Scenario: Change type of a relation into something unknown When loading osm data @@ -77,8 +77,8 @@ Feature: Update of relations by osm2pgsql r1 Ttype=multipolygon,tourism=hotel,name=XY Mw2@ """ Then place contains - | object | class | type | name - | R1 | tourism | hotel | 'name' : 'XZ' + | object | class | type | name | + | R1 | tourism | hotel | 'name' : 'XY' | When updating osm data """ r1 Ttype=multipolygon,amenities=prison,name=XY Mw2@ @@ -96,8 +96,8 @@ Feature: Update of relations by osm2pgsql r1 Ttype=multipolygon,tourism=hotel,name=XY Mw2@ """ Then place contains - | object | class | type | name - | R1 | tourism | hotel | 'name' : 'XZ' + | object | class | type | name | + | R1 | tourism | hotel | 'name' : 'XY' | When updating osm data """ r1 Ttourism=hotel,name=XY Mw2@ @@ -115,8 +115,8 @@ Feature: Update of relations by osm2pgsql r1 Ttype=multipolygon,tourism=hotel,name=XY Mw2@ """ Then place contains - | object | class | type | name - | R1 | tourism | hotel | 'name' : 'XZ' + | object | class | type | name | + | R1 | tourism | hotel | 'name' : 'XY' | When updating osm data """ r1 Ttype=multipolygonn,tourism=hotel,name=XY Mw2@ diff --git a/test/bdd/osm2pgsql/update/simple.feature b/test/bdd/osm2pgsql/update/simple.feature index 33c21039..e8d96d44 100644 --- a/test/bdd/osm2pgsql/update/simple.feature +++ b/test/bdd/osm2pgsql/update/simple.feature @@ -9,10 +9,10 @@ Feature: Update of simple objects by osm2pgsql n2 Tplace=locality,name=spotty """ Then place contains - | object | type | name - | N1:tourism | hotel | 'name' : 'foo' - | N1:amenity | restaurant | 'name' : 'foo' - | N2:place | locality | 'name' : 'spotty' + | object | type | name+name | + | N1:tourism | hotel | foo | + | N1:amenity | restaurant | foo | + | N2:place | locality | spotty | When updating osm data """ n1 dV Ttourism=hotel,name=foo @@ -21,6 +21,6 @@ Feature: Update of simple objects by osm2pgsql Then place has no entry for N1:amenity And place has no entry for N2 And place contains - | object | class | type | name - | N1:tourism | tourism | hotel | 'name' : 'foo' + | object | class | type | name | + | N1:tourism | tourism | hotel | 'name' : 'foo' | diff --git a/test/bdd/steps/cgi-with-coverage.php b/test/bdd/steps/cgi-with-coverage.php index 165a1b0c..47d3cc9a 100644 --- a/test/bdd/steps/cgi-with-coverage.php +++ b/test/bdd/steps/cgi-with-coverage.php @@ -1,6 +1,7 @@ stop(); @@ -16,5 +17,3 @@ $coverage->start($_SERVER['COV_TEST_NAME']); register_shutdown_function('coverage_shutdown', $coverage); include $_SERVER['COV_SCRIPT_FILENAME']; - - diff --git a/test/php/Nominatim/PhraseTest.php b/test/php/Nominatim/PhraseTest.php index db8d8b50..b5e6c1bf 100644 --- a/test/php/Nominatim/PhraseTest.php +++ b/test/php/Nominatim/PhraseTest.php @@ -6,6 +6,8 @@ require_once '../../lib/Phrase.php'; class PhraseTest extends \PHPUnit_Framework_TestCase { + + private function serializeSets($aSets) { $aParts = array(); diff --git a/test/php/Nominatim/SearchContextTest.php b/test/php/Nominatim/SearchContextTest.php index a40d0716..2a74dc41 100644 --- a/test/php/Nominatim/SearchContextTest.php +++ b/test/php/Nominatim/SearchContextTest.php @@ -10,6 +10,7 @@ class SearchContextTest extends \PHPUnit_Framework_TestCase { private $oCtx; + protected function setUp() { $this->oCtx = new SearchContext();