]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge remote-tracking branch 'upstream/master'
authorSarah Hoffmann <lonvia@denofr.de>
Fri, 27 Oct 2017 21:01:11 +0000 (23:01 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Fri, 27 Oct 2017 21:01:11 +0000 (23:01 +0200)
1  2 
lib/Geocode.php
lib/lib.php
sql/functions.sql
utils/update.php
website/reverse.php

diff --combined lib/Geocode.php
index 97fc6371a0faec22eadb00a53dcbd646c4bbaa21,7566d18b8f45e5ca613468cc71a508536c260aa7..8276fe98d6c86d4d4d6d9ad6fafd74757bf949ce
@@@ -19,7 -19,7 +19,7 @@@ class Geocod
      protected $bIncludeAddressDetails = false;
  
      protected $aExcludePlaceIDs = array();
 -    protected $bReverseInPlan = false;
 +    protected $bReverseInPlan = true;
  
      protected $iLimit = 20;
      protected $iFinalLimit = 10;
  
          $sNormQuery = $this->normTerm($this->sQuery);
          $sLanguagePrefArraySQL = getArraySQL(
-             array_map("getDBQuoted", $this->aLangPrefOrder)
+             array_map('getDBQuoted', $this->aLangPrefOrder)
          );
  
          $sQuery = $this->sQuery;
          if (!preg_match('//u', $sQuery)) {
-             userError("Query string is not UTF-8 encoded.");
+             userError('Query string is not UTF-8 encoded.');
          }
  
          // Conflicts between US state abreviations and various words for 'the' in different languages
                  $sSpecialTerm = pg_escape_string($sSpecialTerm);
                  $sToken = chksql(
                      $this->oDB->getOne("SELECT make_standard_name('$sSpecialTerm')"),
-                     "Cannot decode query. Wrong encoding?"
+                     'Cannot decode query. Wrong encoding?'
                  );
                  $sSQL = 'SELECT class, type FROM word ';
                  $sSQL .= '   WHERE word_token in (\' '.$sToken.'\')';
              foreach ($aInPhrases as $iPhrase => $sPhrase) {
                  $sPhrase = chksql(
                      $this->oDB->getOne('SELECT make_standard_name('.getDBQuoted($sPhrase).')'),
-                     "Cannot normalize query string (is it a UTF-8 string?)"
+                     'Cannot normalize query string (is it a UTF-8 string?)'
                  );
                  if (trim($sPhrase)) {
                      $oPhrase = new Phrase($sPhrase, is_string($iPhrase) ? $iPhrase : '');
                  // Check which tokens we have, get the ID numbers
                  $sSQL = 'SELECT word_id, word_token, word, class, type, country_code, operator, search_name_count';
                  $sSQL .= ' FROM word ';
-                 $sSQL .= ' WHERE word_token in ('.join(',', array_map("getDBQuoted", $aTokens)).')';
+                 $sSQL .= ' WHERE word_token in ('.join(',', array_map('getDBQuoted', $aTokens)).')';
  
                  if (CONST_Debug) var_Dump($sSQL);
  
                  $aValidTokens = array();
                  $aDatabaseWords = chksql(
                      $this->oDB->getAll($sSQL),
-                     "Could not get word tokens."
+                     'Could not get word tokens.'
                  );
                  $aWordFrequencyScores = array();
                  foreach ($aDatabaseWords as $aToken) {
                      if ($sPlaceIds) {
                          $sSQL = 'SELECT place_id FROM placex ';
                          $sSQL .= 'WHERE place_id in ('.$sPlaceIds.') ';
-                         $sSQL .= "  AND (";
+                         $sSQL .= '  AND (';
                          $sSQL .= "         placex.rank_address between $this->iMinAddressRank and $this->iMaxAddressRank ";
                          if (14 >= $this->iMinAddressRank && 14 <= $this->iMaxAddressRank) {
                              $sSQL .= "     OR (extratags->'place') = 'city'";
                          }
                          if ($this->aAddressRankList) {
-                             $sSQL .= "     OR placex.rank_address in (".join(',', $this->aAddressRankList).")";
+                             $sSQL .= '     OR placex.rank_address in ('.join(',', $this->aAddressRankList).')';
                          }
-                         $sSQL .= ")";
+                         $sSQL .= ')';
                          $aFilterSql[] = $sSQL;
                      }
                      $sPlaceIds = Result::joinIdsByTable($aResults, Result::TABLE_POSTCODE);
                          $sSQL .= 'WHERE place_id in ('.$sPlaceIds.') ';
                          $sSQL .= "  AND (lp.rank_address between $this->iMinAddressRank and $this->iMaxAddressRank ";
                          if ($this->aAddressRankList) {
-                             $sSQL .= "     OR lp.rank_address in (".join(',', $this->aAddressRankList).")";
+                             $sSQL .= '     OR lp.rank_address in ('.join(',', $this->aAddressRankList).')';
                          }
-                         $sSQL .= ") ";
+                         $sSQL .= ') ';
                          $aFilterSql[] = $sSQL;
                      }
  
  
              $oLookup = $oReverse->lookupPoint($oCtx->sqlNear, false);
  
-             if (CONST_Debug) var_dump("Reverse search", $aLookup);
+             if (CONST_Debug) var_dump('Reverse search', $aLookup);
  
              if ($oLookup) {
                  $aResults = array($oLookup->iId => $oLookup);
                  foreach ($aRecheckWords as $i => $sWord) {
                      if (stripos($sAddress, $sWord)!==false) {
                          $iCountWords++;
-                         if (preg_match("/(^|,)\s*".preg_quote($sWord, '/')."\s*(,|$)/", $sAddress)) $iCountWords += 0.1;
+                         if (preg_match('/(^|,)\s*'.preg_quote($sWord, '/').'\s*(,|$)/', $sAddress)) $iCountWords += 0.1;
                      }
                  }
  
diff --combined lib/lib.php
index 9bf15964bd9410397d3f91ae4cafdd1e3447f3f4,b5c4df133b9e79cda4fa8f33b4cf93516132865d..6c56d5d93e435da4c10724f44cb746b8f4ffb64a
@@@ -38,7 -38,7 +38,7 @@@ function getDatabaseDate(&$oDB
      // Find the newest node in the DB
      $iLastOSMID = $oDB->getOne("select max(osm_id) from place where osm_type = 'N'");
      // Lookup the timestamp that node was created
-     $sLastNodeURL = 'https://www.openstreetmap.org/api/0.6/node/'.$iLastOSMID."/1";
+     $sLastNodeURL = 'https://www.openstreetmap.org/api/0.6/node/'.$iLastOSMID.'/1';
      $sLastNodeXML = file_get_contents($sLastNodeURL);
  
      if ($sLastNodeXML === false) {
@@@ -413,11 -413,11 +413,11 @@@ function javascript_renderData($xVal, $
      $jsonout = json_encode($xVal, $iOptions);
  
      if (!isset($_GET['json_callback'])) {
-         header("Content-Type: application/json; charset=UTF-8");
+         header('Content-Type: application/json; charset=UTF-8');
          echo $jsonout;
      } else {
          if (preg_match('/^[$_\p{L}][$_\p{L}\p{Nd}.[\]]*$/u', $_GET['json_callback'])) {
-             header("Content-Type: application/javascript; charset=UTF-8");
+             header('Content-Type: application/javascript; charset=UTF-8');
              echo $_GET['json_callback'].'('.$jsonout.')';
          } else {
              header('HTTP/1.0 400 Bad Request');
@@@ -439,16 -439,16 +439,16 @@@ function _debugDumpGroupedSearches($aDa
              }
          }
      }
-     echo "<table border=\"1\">";
-     echo "<tr><th>rank</th><th>Name Tokens</th><th>Name Not</th>";
-     echo "<th>Address Tokens</th><th>Address Not</th><th>country</th><th>operator</th>";
-     echo "<th>class</th><th>type</th><th>postcode</th><th>housenumber</th></tr>";
+     echo '<table border="1">';
+     echo '<tr><th>rank</th><th>Name Tokens</th><th>Name Not</th>';
+     echo '<th>Address Tokens</th><th>Address Not</th><th>country</th><th>operator</th>';
+     echo '<th>class</th><th>type</th><th>postcode</th><th>housenumber</th></tr>';
      foreach ($aData as $iRank => $aRankedSet) {
          foreach ($aRankedSet as $aRow) {
              $aRow->dumpAsHtmlTableRow($aWordsIDs);
          }
      }
-     echo "</table>";
+     echo '</table>';
  }
  
  
@@@ -456,7 -456,7 +456,7 @@@ function getAddressDetails(&$oDB, $sLan
  {
      $sSQL = "select *,get_name_by_language(name,$sLanguagePrefArraySQL) as localname from get_addressdata($iPlaceID, $housenumber)";
      if (!$bRaw) $sSQL .= " WHERE isaddress OR type = 'country_code'";
-     $sSQL .= " order by rank_address desc,isaddress desc";
+     $sSQL .= ' order by rank_address desc,isaddress desc';
  
      $aAddressLines = chksql($oDB->getAll($sSQL));
      if ($bRaw) return $aAddressLines;
@@@ -584,10 -584,10 +584,10 @@@ function geometryText2Points($geometry_
          //
          preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER);
          //
 -    } elseif (preg_match('#MULTIPOLYGON\\(\\(\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) {
 +/*    } elseif (preg_match('#MULTIPOLYGON\\(\\(\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) {
          //
          preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER);
 -        //
 +        */
      } elseif (preg_match('#POINT\\((-?[0-9.]+) (-?[0-9.]+)\\)#', $geometry_as_text, $aMatch)) {
          //
          $aPolyPoints = createPointsAroundCenter($aMatch[1], $aMatch[2], $fRadius);
diff --combined sql/functions.sql
index 97baf52b74520b0dc312b0189a6d232ba45ddae7,1691e23573cef829c0d788298708e66775189b68..e5e189a8f7766f9c114a60deec78bce0e0c9046a
@@@ -2503,13 -2503,13 +2503,13 @@@ BEGI
      select placex.place_id, osm_type, osm_id, name,
        CASE WHEN extratags ? 'place' THEN 'place' ELSE class END as class,
        CASE WHEN extratags ? 'place' THEN extratags->'place' ELSE type END as type,
 -      admin_level, fromarea, isaddress,
 +      admin_level, fromarea, isaddress and linked_place_id is NULL as isaddress,
        CASE WHEN address_place_id = for_place_id AND rank_address = 0 THEN 100 WHEN rank_address = 11 THEN 5 ELSE rank_address END as rank_address,
        distance,country_code,postcode
        from place_addressline join placex on (address_place_id = placex.place_id) 
        where place_addressline.place_id = for_place_id 
        and (cached_rank_address > 0 AND cached_rank_address < searchrankaddress)
-       and address_place_id != for_place_id
+       and address_place_id != for_place_id and linked_place_id is null
        and (placex.country_code IS NULL OR searchcountrycode IS NULL OR placex.country_code = searchcountrycode)
        order by rank_address desc,isaddress desc,fromarea desc,distance asc,rank_search desc
    LOOP
diff --combined utils/update.php
index 3026dacb5b0ecb235f51a86881dedf5b1b309358,5a5d41fff8435f2c2c9cd50d16a004704458d3ba..006a4774fa0792edb79f2c8d0dbe245d8ed06efb
@@@ -7,7 -7,7 +7,7 @@@ ini_set('memory_limit', '800M')
  
  $aCMDOptions
  = array(
-    "Import / update / index osm data",
+    'Import / update / index osm data',
     array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
     array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
     array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
@@@ -38,7 -38,6 +38,7 @@@
  getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true);
  
  if (!isset($aResult['index-instances'])) $aResult['index-instances'] = 1;
 +
  if (!isset($aResult['index-rank'])) $aResult['index-rank'] = 0;
  
  date_default_timezone_set('Etc/UTC');
@@@ -65,7 -64,7 +65,7 @@@ if ($aResult['init-updates']) 
      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.");
+         fail('replication URL not reachable.');
      }
      $sSetup = CONST_InstallPath.'/utils/setup.php';
      $iRet = -1;
@@@ -76,7 -75,7 +76,7 @@@
  
      $sDatabaseDate = getDatabaseDate($oDB);
      if ($sDatabaseDate === false) {
-         fail("Cannot determine date of database.");
+         fail('Cannot determine date of database.');
      }
      $sWindBack = strftime('%Y-%m-%dT%H:%M:%SZ', strtotime($sDatabaseDate) - (3*60*60));
  
@@@ -90,9 -89,9 +90,9 @@@
  
      pg_query($oDB->connection, 'TRUNCATE import_status');
      $sSQL = "INSERT INTO import_status (lastimportdate, sequence_id, indexed) VALUES('";
-     $sSQL .= $sDatabaseDate."',".$aOutput[0].", true)";
+     $sSQL .= $sDatabaseDate."',".$aOutput[0].', true)';
      if (!pg_query($oDB->connection, $sSQL)) {
-         fail("Could not enter sequence into database.");
+         fail('Could not enter sequence into database.');
      }
  
      echo "Done. Database updates will start at sequence $aOutput[0] ($sWindBack)\n";
@@@ -119,7 -118,7 +119,7 @@@ if (isset($aResult['import-diff']) || i
  }
  
  if ($aResult['calculate-postcodes']) {
-     info("Update postcodes centroids");
+     info('Update postcodes centroids');
      $sTemplate = file_get_contents(CONST_BasePath.'/sql/update-postcodes.sql');
      runSQLScript($sTemplate, true, true);
  }
@@@ -171,7 -170,7 +171,7 @@@ if ($aResult['deduplicate']) 
      $oDB =& getDB();
  
      if (getPostgresVersion($oDB) < 9.3) {
-         fail("ERROR: deduplicate is only currently supported in postgresql 9.3");
+         fail('ERROR: deduplicate is only currently supported in postgresql 9.3');
      }
  
      $sSQL = 'select partition from country_name order by country_code';
  
      // we don't care about empty search_name_* partitions, they can't contain mentions of duplicates
      foreach ($aPartitions as $i => $sPartition) {
-         $sSQL = "select count(*) from search_name_".$sPartition;
+         $sSQL = 'select count(*) from search_name_'.$sPartition;
          $nEntries = chksql($oDB->getOne($sSQL));
          if ($nEntries == 0) {
              unset($aPartitions[$i]);
      }
  
      $sSQL = "select word_token,count(*) from word where substr(word_token, 1, 1) = ' '";
-     $sSQL .= " and class is null and type is null and country_code is null";
-     $sSQL .= " group by word_token having count(*) > 1 order by word_token";
+     $sSQL .= ' and class is null and type is null and country_code is null';
+     $sSQL .= ' group by word_token having count(*) > 1 order by word_token';
      $aDuplicateTokens = chksql($oDB->getAll($sSQL));
      foreach ($aDuplicateTokens as $aToken) {
          if (trim($aToken['word_token']) == '' || trim($aToken['word_token']) == '-') continue;
-         echo "Deduping ".$aToken['word_token']."\n";
-         $sSQL = "select word_id,";
-         $sSQL .= " (select count(*) from search_name where nameaddress_vector @> ARRAY[word_id]) as num";
+         echo 'Deduping '.$aToken['word_token']."\n";
+         $sSQL = 'select word_id,';
+         $sSQL .= ' (select count(*) from search_name where nameaddress_vector @> ARRAY[word_id]) as num';
          $sSQL .= " from word where word_token = '".$aToken['word_token'];
          $sSQL .= "' and class is null and type is null and country_code is null order by num desc";
          $aTokenSet = chksql($oDB->getAll($sSQL));
          $iKeepID = $aKeep['word_id'];
  
          foreach ($aTokenSet as $aRemove) {
-             $sSQL = "update search_name set";
-             $sSQL .= " name_vector = array_replace(name_vector,".$aRemove['word_id'].",".$iKeepID."),";
-             $sSQL .= " nameaddress_vector = array_replace(nameaddress_vector,".$aRemove['word_id'].",".$iKeepID.")";
-             $sSQL .= " where name_vector @> ARRAY[".$aRemove['word_id']."]";
+             $sSQL = 'update search_name set';
+             $sSQL .= ' name_vector = array_replace(name_vector,'.$aRemove['word_id'].','.$iKeepID.'),';
+             $sSQL .= ' nameaddress_vector = array_replace(nameaddress_vector,'.$aRemove['word_id'].','.$iKeepID.')';
+             $sSQL .= ' where name_vector @> ARRAY['.$aRemove['word_id'].']';
              chksql($oDB->query($sSQL));
  
-             $sSQL = "update search_name set";
-             $sSQL .= " nameaddress_vector = array_replace(nameaddress_vector,".$aRemove['word_id'].",".$iKeepID.")";
-             $sSQL .= " where nameaddress_vector @> ARRAY[".$aRemove['word_id']."]";
+             $sSQL = 'update search_name set';
+             $sSQL .= ' nameaddress_vector = array_replace(nameaddress_vector,'.$aRemove['word_id'].','.$iKeepID.')';
+             $sSQL .= ' where nameaddress_vector @> ARRAY['.$aRemove['word_id'].']';
              chksql($oDB->query($sSQL));
  
-             $sSQL = "update location_area_country set";
-             $sSQL .= " keywords = array_replace(keywords,".$aRemove['word_id'].",".$iKeepID.")";
-             $sSQL .= " where keywords @> ARRAY[".$aRemove['word_id']."]";
+             $sSQL = 'update location_area_country set';
+             $sSQL .= ' keywords = array_replace(keywords,'.$aRemove['word_id'].','.$iKeepID.')';
+             $sSQL .= ' where keywords @> ARRAY['.$aRemove['word_id'].']';
              chksql($oDB->query($sSQL));
  
              foreach ($aPartitions as $sPartition) {
-                 $sSQL = "update search_name_".$sPartition." set";
-                 $sSQL .= " name_vector = array_replace(name_vector,".$aRemove['word_id'].",".$iKeepID.")";
-                 $sSQL .= " where name_vector @> ARRAY[".$aRemove['word_id']."]";
+                 $sSQL = 'update search_name_'.$sPartition.' set';
+                 $sSQL .= ' name_vector = array_replace(name_vector,'.$aRemove['word_id'].','.$iKeepID.')';
+                 $sSQL .= ' where name_vector @> ARRAY['.$aRemove['word_id'].']';
                  chksql($oDB->query($sSQL));
  
-                 $sSQL = "update location_area_country set";
-                 $sSQL .= " keywords = array_replace(keywords,".$aRemove['word_id'].",".$iKeepID.")";
-                 $sSQL .= " where keywords @> ARRAY[".$aRemove['word_id']."]";
+                 $sSQL = 'update location_area_country set';
+                 $sSQL .= ' keywords = array_replace(keywords,'.$aRemove['word_id'].','.$iKeepID.')';
+                 $sSQL .= ' where keywords @> ARRAY['.$aRemove['word_id'].']';
                  chksql($oDB->query($sSQL));
              }
  
-             $sSQL = "delete from word where word_id = ".$aRemove['word_id'];
+             $sSQL = 'delete from word where word_id = '.$aRemove['word_id'];
              chksql($oDB->query($sSQL));
          }
      }
@@@ -361,7 -360,7 +361,7 @@@ if ($aResult['import-osmosis'] || $aRes
              $oDB->query($sSQL);
              echo date('Y-m-d H:i:s')." Completed index step for $sBatchEnd in ".round((time()-$fCMDStartTime)/60, 2)." minutes\n";
  
-             $sSQL = "update import_status set indexed = true";
+             $sSQL = 'update import_status set indexed = true';
              $oDB->query($sSQL);
          }
  
diff --combined website/reverse.php
index 41e1a725d0eb610ae8b6126e945a4bbad3bf7203,b6d0f5e6de0b3d406bfc99f94ab25cf349403650..d997088a04b94d5c1e33e633eab06eeed129ebe3
@@@ -46,7 -46,7 +46,7 @@@ if ($sOsmType && $iOsmId > 0) 
          }
      }
  } elseif ($sOutputFormat != 'html') {
-     userError("Need coordinates or OSM object to lookup.");
+     userError('Need coordinates or OSM object to lookup.');
  }
  
  if (isset($aPlace)) {
@@@ -65,7 -65,6 +65,7 @@@
      $aPlace = [];
  }
  
 +logEnd($oDB, $hLog, sizeof($aPlace)?1:0);
  
  if (CONST_Debug) {
      var_dump($aPlace);