]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge remote-tracking branch 'upstream/master'
authorSarah Hoffmann <lonvia@denofr.de>
Thu, 1 Mar 2018 22:48:45 +0000 (23:48 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Thu, 1 Mar 2018 22:48:45 +0000 (23:48 +0100)
25 files changed:
.travis.yml
CONTRIBUTING.md
docs/CMakeLists.txt
docs/admin/Faq.md
docs/admin/Installation.md
docs/develop/overview.md [new file with mode: 0644]
docs/mkdocs.yml
lib/SearchContext.php
lib/SearchDescription.php
lib/template/address-json.php
lib/template/address-jsonv2.php
lib/template/address-xml.php
lib/template/search-batch-json.php
lib/template/search-json.php
lib/template/search-jsonv2.php
lib/template/search-xml.php
module/nominatim.c
phpcs.xml
test/bdd/db/import/parenting.feature
test/bdd/db/import/postcodes.feature
test/bdd/osm2pgsql/update/relation.feature
test/bdd/osm2pgsql/update/simple.feature
test/bdd/steps/cgi-with-coverage.php
test/php/Nominatim/PhraseTest.php
test/php/Nominatim/SearchContextTest.php

index 5efc9f083171489a6d391896047c52afb322cdda..c67f155e4240a1b5e2a0e0e08d0b1937143f36c7 100644 (file)
@@ -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
index a00d0ed354aa68ac5ffe4a00d107253f4c62874d..dc5be190ad7633ec325241f48fd977b65f786f75 100644 (file)
@@ -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
index e8596e49f81818314e61333b1a5751fdf84a1df0..d2fe03d018729981128ed7a392949f128229fe81 100644 (file)
@@ -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
index 470e936c95f159bcaa30101a589c01f07c71a0a0..a1624d263a83b38bd141148013bffbbe3808cd15 100644 (file)
@@ -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`.
index ce7fb412fff8ab69d333a8501e2d488d7c8797f6..67c4fe3c6687639423ef3ed465619ee1516347c8 100644 (file)
@@ -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 (file)
index 0000000..179eeb0
--- /dev/null
@@ -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.
index d647dd8717a9fd9984d63ea8cf16083275a8ddfc..b0aee5d07fa714238661b2c8b024498455aa2cfe 100644 (file)
@@ -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'
index 3e722d87af9b318c055fcae60058298061a0b20f..b0ff38d85c05e70a003968571cfa207445ebd8f8 100644 (file)
@@ -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()
     {
index 6b66e5a552342724a03aee2d79d45768c24981f8..a1910231ef8b53285ff561b52f1a00a1191c88ab 100644 (file)
@@ -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;
+                }
             }
         }
 
index 93abb6017308b485c7634bc9a89fe1d670a07f03..cea8774549cef955eb4c91a783cdccbb835f692c 100644 (file)
@@ -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);
-
index 229303be6e7325bb19de208299b7323300c3c977..399c978f6701d823539af592a678526f33091e9c 100644 (file)
@@ -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);
index d3db2eddaeb04ac376e0535b1499587fc94c7470..6183b284dbc3e8df471ffc719e438e1de83dd17a 100644 (file)
 <?php
-header("content-type: text/xml; charset=UTF-8");
+header('content-type: text/xml; charset=UTF-8');
 
-echo "<";
-echo "?xml version=\"1.0\" encoding=\"UTF-8\" ?";
+echo '<';
+echo '?xml version="1.0" encoding="UTF-8" ?';
 echo ">\n";
 
-echo "<reversegeocode";
+echo '<reversegeocode';
 echo " timestamp='".date(DATE_RFC822)."'";
 echo " attribution='Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright'";
 echo " querystring='".htmlspecialchars($_SERVER['QUERY_STRING'], ENT_QUOTES)."'";
 echo ">\n";
 
-if (!sizeof($aPlace))
-{
+if (!sizeof($aPlace)) {
     if (isset($sError))
         echo "<error>$sError</error>";
-    else
-        echo "<error>Unable to geocode</error>";
-}
-else
-{
-    echo "<result";
+    else echo '<error>Unable to geocode</error>';
+} else {
+    echo '<result';
     if ($aPlace['place_id']) echo ' place_id="'.$aPlace['place_id'].'"';
     $sOSMType = formatOSMType($aPlace['osm_type']);
     if ($sOSMType) echo ' osm_type="'.$sOSMType.'"'.' osm_id="'.$aPlace['osm_id'].'"';
     if ($aPlace['ref']) echo ' ref="'.htmlspecialchars($aPlace['ref']).'"';
     if (isset($aPlace['lat'])) echo ' lat="'.htmlspecialchars($aPlace['lat']).'"';
     if (isset($aPlace['lon'])) echo ' lon="'.htmlspecialchars($aPlace['lon']).'"';
-    if (isset($aPlace['aBoundingBox']))
-    {
+    if (isset($aPlace['aBoundingBox'])) {
         echo ' boundingbox="';
         echo join(',', $aPlace['aBoundingBox']);
         echo '"';
     }
 
-    if (isset($aPlace['asgeojson']))
-    {
+    if (isset($aPlace['asgeojson'])) {
         echo ' geojson=\'';
         echo $aPlace['asgeojson'];
         echo '\'';
     }
 
-    if (isset($aPlace['assvg']))
-    {
+    if (isset($aPlace['assvg'])) {
         echo ' geosvg=\'';
         echo $aPlace['assvg'];
         echo '\'';
     }
 
-    if (isset($aPlace['astext']))
-    {
+    if (isset($aPlace['astext'])) {
         echo ' geotext=\'';
         echo $aPlace['astext'];
         echo '\'';
     }
-    echo ">".htmlspecialchars($aPlace['langaddress'])."</result>";
+    echo '>'.htmlspecialchars($aPlace['langaddress']).'</result>';
 
-    if (isset($aPlace['aAddress']))
-    {
-        echo "<addressparts>";
-        foreach($aPlace['aAddress'] as $sKey => $sValue)
-        {
-            $sKey = str_replace(' ','_',$sKey);
+    if (isset($aPlace['aAddress'])) {
+        echo '<addressparts>';
+        foreach ($aPlace['aAddress'] as $sKey => $sValue) {
+            $sKey = str_replace(' ', '_', $sKey);
             echo "<$sKey>";
             echo htmlspecialchars($sValue);
             echo "</$sKey>";
         }
-        echo "</addressparts>";
+        echo '</addressparts>';
     }
 
-    if (isset($aPlace['sExtraTags']))
-    {
-        echo "<extratags>";
-        foreach ($aPlace['sExtraTags'] as $sKey => $sValue)
-        {
+    if (isset($aPlace['sExtraTags'])) {
+        echo '<extratags>';
+        foreach ($aPlace['sExtraTags'] as $sKey => $sValue) {
             echo '<tag key="'.htmlspecialchars($sKey).'" value="'.htmlspecialchars($sValue).'"/>';
         }
-        echo "</extratags>";
+        echo '</extratags>';
     }
 
-    if (isset($aPlace['sNameDetails']))
-    {
-        echo "<namedetails>";
-        foreach ($aPlace['sNameDetails'] as $sKey => $sValue)
-        {
+    if (isset($aPlace['sNameDetails'])) {
+        echo '<namedetails>';
+        foreach ($aPlace['sNameDetails'] as $sKey => $sValue) {
             echo '<name desc="'.htmlspecialchars($sKey).'">';
             echo htmlspecialchars($sValue);
-            echo "</name>";
+            echo '</name>';
         }
-        echo "</namedetails>";
+        echo '</namedetails>';
     }
 
-    if (isset($aPlace['askml']))
-    {
+    if (isset($aPlace['askml'])) {
         echo "\n<geokml>";
         echo $aPlace['askml'];
-        echo "</geokml>";
+        echo '</geokml>';
     }
-
 }
 
-echo "</reversegeocode>";
+echo '</reversegeocode>';
index a3ced45bc35bb46ec3fab5be00f04229a952a507..09ea48b63bdbc2a964ac4134de5fcd0d43084dfb 100644 (file)
@@ -1,42 +1,37 @@
 <?php
 
 $aOutput = array();
-$aOutput['licence'] = "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright";
+$aOutput['licence'] = 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright';
 $aOutput['batch'] = array();
 
-foreach($aBatchResults as $aSearchResults)
-{
+foreach ($aBatchResults as $aSearchResults) {
     if (!$aSearchResults) $aSearchResults = array();
     $aFilteredPlaces = array();
-    foreach($aSearchResults as $iResNum => $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'];
         }
 
index 846d654c5e3b5fb5da8b317ccb5cf9319d03a268..b997f6d97b1fcb01f7ed12b74f8f3468b5d8377a 100644 (file)
@@ -1,33 +1,28 @@
 <?php
-header("content-type: application/json; charset=UTF-8");
+header('content-type: application/json; charset=UTF-8');
 
 $aFilteredPlaces = array();
-foreach($aSearchResults as $iResNum => $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'];
     }
 
index 5d2802afe60b36f8d5351410832adaf5a9feb4bf..7610330419435279101c01b432d3f468fb97f525 100644 (file)
@@ -1,32 +1,27 @@
 <?php
 
 $aFilteredPlaces = array();
-foreach($aSearchResults as $iResNum => $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'];
     }
 
index 80414fce6829be2f18534e06431aabbb2b9f8db3..94bb7ec96a44cdbfae7a150e6044883650a4ead2 100644 (file)
@@ -1,72 +1,63 @@
 <?php
-header("content-type: text/xml; charset=UTF-8");
+header('content-type: text/xml; charset=UTF-8');
 
-echo "<";
-echo "?xml version=\"1.0\" encoding=\"UTF-8\" ?";
+echo '<';
+echo '?xml version="1.0" encoding="UTF-8" ?';
 echo ">\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 "<place place_id='".$aResult['place_id']."'";
     $sOSMType = formatOSMType($aResult['osm_type']);
-    if ($sOSMType)
-    {
+    if ($sOSMType) {
         echo " osm_type='$sOSMType'";
         echo " osm_id='".$aResult['osm_id']."'";
     }
     echo " place_rank='".$aResult['rank_search']."'";
 
-    if (isset($aResult['aBoundingBox']))
-    {
+    if (isset($aResult['aBoundingBox'])) {
         echo ' boundingbox="';
-        echo join(',',$aResult['aBoundingBox']);
+        echo join(',', $aResult['aBoundingBox']);
         echo '"';
 
-        if (isset($aResult['aPolyPoints']))
-        {
+        if (isset($aResult['aPolyPoints'])) {
             echo ' polygonpoints=\'';
             echo json_encode($aResult['aPolyPoints']);
             echo '\'';
         }
     }
 
-    if (isset($aResult['asgeojson']))
-    {
+    if (isset($aResult['asgeojson'])) {
         echo ' geojson=\'';
         echo $aResult['asgeojson'];
         echo '\'';
     }
 
-    if (isset($aResult['assvg']))
-    {
+    if (isset($aResult['assvg'])) {
         echo ' geosvg=\'';
         echo $aResult['assvg'];
         echo '\'';
     }
 
-    if (isset($aResult['astext']))
-    {
+    if (isset($aResult['astext'])) {
         echo ' geotext=\'';
         echo $aResult['astext'];
         echo '\'';
     }
 
-    if (isset($aResult['zoom']))
-    {
+    if (isset($aResult['zoom'])) {
         echo " zoom='".$aResult['zoom']."'";
     }
 
@@ -77,82 +68,67 @@ foreach($aSearchResults as $iResNum => $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<geokml>";
         echo $aResult['askml'];
-        echo "</geokml>";
+        echo '</geokml>';
     }
 
-    if (isset($aResult['sExtraTags']))
-    {
-        if (!$bHasDelim)
-        {
+    if (isset($aResult['sExtraTags'])) {
+        if (!$bHasDelim) {
             $bHasDelim = true;
-            echo ">";
+            echo '>';
         }
         echo "\n<extratags>";
-        foreach ($aResult['sExtraTags'] as $sKey => $sValue)
-        {
+        foreach ($aResult['sExtraTags'] as $sKey => $sValue) {
             echo '<tag key="'.htmlspecialchars($sKey).'" value="'.htmlspecialchars($sValue).'"/>';
         }
-        echo "</extratags>";
+        echo '</extratags>';
     }
 
-    if (isset($aResult['sNameDetails']))
-    {
-        if (!$bHasDelim)
-        {
+    if (isset($aResult['sNameDetails'])) {
+        if (!$bHasDelim) {
             $bHasDelim = true;
-            echo ">";
+            echo '>';
         }
         echo "\n<namedetails>";
-        foreach ($aResult['sNameDetails'] as $sKey => $sValue)
-        {
+        foreach ($aResult['sNameDetails'] as $sKey => $sValue) {
             echo '<name desc="'.htmlspecialchars($sKey).'">';
             echo htmlspecialchars($sValue);
-            echo "</name>";
+            echo '</name>';
         }
-        echo "</namedetails>";
+        echo '</namedetails>';
     }
 
-    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 "</$sKey>";
         }
     }
 
-    if ($bHasDelim)
-    {
-        echo "</place>";
-    }
-    else
-    {
-        echo "/>";
+    if ($bHasDelim) {
+        echo '</place>';
+    } else {
+        echo '/>';
     }
 }
 
-echo "</" . (isset($sXmlRootTag)?$sXmlRootTag:'searchresults') . ">";
+echo '</' . (isset($sXmlRootTag)?$sXmlRootTag:'searchresults') . '>';
index 75238e2207ff172aad46771569b091d7e73980d5..73bf16c8df487eac4d462621fe566534e6476621 100644 (file)
@@ -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;
index 8f92f7c99078b87ca7f0bfd213fe93bfe5c44315..a48b5c3e608db00b6ad24a4e3d979af7537e581d 100644 (file)
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -8,6 +8,12 @@
   <!-- https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PSR2/ruleset.xml -->
   <rule ref="PSR2"/>
 
+  <exclude-pattern>./lib/template/*html*</exclude-pattern>
+  <exclude-pattern>./lib/template/includes/</exclude-pattern>
+  <exclude-pattern>./module/</exclude-pattern>
+  <exclude-pattern>./website/css</exclude-pattern>
+  <exclude-pattern>./website/js</exclude-pattern>
+
   <rule ref="Generic.Files.LineLength">
     <properties>
      <property name="lineLimit" value="194"/>
        INDENTATION, SPACING
        ************************************************************** -->
 
-  <!-- We don't need 2 blank lines after function -->
-  <rule ref="Squiz.WhiteSpace.FunctionSpacing.After">
-    <severity>0</severity>
-  </rule>
-
-  <!-- Aligned looks nicer, but causes too many warnings currently -->
-  <rule ref="Generic.Formatting.MultipleStatementAlignment.NotSame">
-    <severity>0</severity>
-  </rule>
-  <rule ref="Generic.Formatting.MultipleStatementAlignment.NotSameWarning">
-    <severity>0</severity>
-  </rule>
-
   <!-- Aligned looks nicer, but causes too many warnings currently -->
   <rule ref="Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned">
     <severity>0</severity>
index 401a58f14676dd08425bb6395c8b4ae42b6fa582..87467fd287a22603d2c1c10f9c8384adfcba6f26 100644 (file)
@@ -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
index be469fe6b158b6141a667b5966f1a9ecdf531117..4c49dc5bf7d812a310241f1c6279b8480e054de0 100644 (file)
@@ -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 |
index 83ce912989f46b20c8a4b3d348f3d6a6c1ded7d9..fd8b83e3c07cfc07a7bfa7329973afae84852a95 100644 (file)
@@ -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@
index 33c21039e1425a5a4dc4487407de86a643d2720e..e8d96d44e3e372733b5abf1247314452d50c0159 100644 (file)
@@ -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' |
 
index 165a1b0cd9b312870b4bff750287e865f9ee9e51..47d3cc9ac6760c248cda6a0f56a33f726b302a90 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 require_once 'SebastianBergmann/CodeCoverage/autoload.php';
 
+
 function coverage_shutdown($oCoverage)
 {
     $oCoverage->stop();
@@ -16,5 +17,3 @@ $coverage->start($_SERVER['COV_TEST_NAME']);
 register_shutdown_function('coverage_shutdown', $coverage);
 
 include $_SERVER['COV_SCRIPT_FILENAME'];
-
-
index db8d8b50808ad8325dbcc769908d5fcbe0ee7d7b..b5e6c1bf6e666b0f3a6c631648f3bc24865566e6 100644 (file)
@@ -6,6 +6,8 @@ require_once '../../lib/Phrase.php';
 
 class PhraseTest extends \PHPUnit_Framework_TestCase
 {
+
+
     private function serializeSets($aSets)
     {
         $aParts = array();
index a40d0716aa25a9f635b6b1919f4a2342a88b4ab3..2a74dc41c5b6a21cb14bab50257b95e5e19c309f 100644 (file)
@@ -10,6 +10,7 @@ class SearchContextTest extends \PHPUnit_Framework_TestCase
 {
     private $oCtx;
 
+
     protected function setUp()
     {
         $this->oCtx = new SearchContext();