]> git.openstreetmap.org Git - nominatim.git/blobdiff - utils/update.php
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / utils / update.php
index 7448348f14cfb99bad81b045380eaa67ab8b8a5a..a561aaa3656cc88ebf9099027bda7c63412425c4 100755 (executable)
@@ -73,6 +73,7 @@
        $oDB =& getDB();
 
        $aDSNInfo = DB::parseDSN(CONST_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
        $iCacheMemory = (isset($aResult['osm2pgsql-cache'])?$aResult['osm2pgsql-cache']:2000);
@@ -81,7 +82,7 @@
                $iCacheMemory = getCacheMemoryMB();
                echo "WARNING: resetting cache memory to $iCacheMemory\n";
        }
-       $sOsm2pgsqlCmd = CONST_Osm2pgsql_Binary.' -klas -C '.$iCacheMemory.' -O gazetteer -d '.$aDSNInfo['database'];
+       $sOsm2pgsqlCmd = CONST_Osm2pgsql_Binary.' -klas -C '.$iCacheMemory.' -O gazetteer -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'];
        if (!is_null(CONST_Osm2pgsql_Flatnode_File))
        {
                $sOsm2pgsqlCmd .= ' --flat-nodes '.CONST_Osm2pgsql_Flatnode_File;
 
        if ($aResult['deduplicate'])
        {
+
+               $pgver = (float) CONST_Postgresql_Version;
+                if ($pgver < 9.3) {
+                       echo "ERROR: deduplicate is only currently supported in postgresql 9.3";
+                       exit;
+               }
+
                 $oDB =& getDB();
                 $sSQL = 'select partition from country_name order by country_code';
                 $aPartitions = $oDB->getCol($sSQL);
                                var_dump($aTokenSet, $sSQL);
                                exit;
                        }
-                       
+
                        $aKeep = array_shift($aTokenSet);
                        $iKeepID = $aKeep['word_id'];
 
                        foreach($aTokenSet as $aRemove)
                        {
                                $sSQL = "update search_name set";
-                               $sSQL .= " name_vector = (name_vector - ".$aRemove['word_id'].")+".$iKeepID.",";
-                               $sSQL .= " nameaddress_vector = (nameaddress_vector - ".$aRemove['word_id'].")+".$iKeepID;
+                               $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']."]";
                                $x = $oDB->query($sSQL);
                                if (PEAR::isError($x))
                                }
 
                                $sSQL = "update search_name set";
-                               $sSQL .= " nameaddress_vector = (nameaddress_vector - ".$aRemove['word_id'].")+".$iKeepID;
+                               $sSQL .= " nameaddress_vector = array_replace(nameaddress_vector,".$aRemove['word_id'].",".$iKeepID.")";
                                $sSQL .= " where nameaddress_vector @> ARRAY[".$aRemove['word_id']."]";
                                $x = $oDB->query($sSQL);
                                if (PEAR::isError($x))
                                }
 
                                $sSQL = "update location_area_country set";
-                               $sSQL .= " keywords = (keywords - ".$aRemove['word_id'].")+".$iKeepID;
+                               $sSQL .= " keywords = array_replace(keywords,".$aRemove['word_id'].",".$iKeepID.")";
                                $sSQL .= " where keywords @> ARRAY[".$aRemove['word_id']."]";
                                $x = $oDB->query($sSQL);
                                if (PEAR::isError($x))
                                foreach ($aPartitions as $sPartition)
                                {
                                        $sSQL = "update search_name_".$sPartition." set";
-                                       $sSQL .= " name_vector = (name_vector - ".$aRemove['word_id'].")+".$iKeepID.",";
-                                       $sSQL .= " nameaddress_vector = (nameaddress_vector - ".$aRemove['word_id'].")+".$iKeepID;
+                                       $sSQL .= " name_vector = array_replace(name_vector,".$aRemove['word_id'].",".$iKeepID.")";
                                        $sSQL .= " where name_vector @> ARRAY[".$aRemove['word_id']."]";
                                        $x = $oDB->query($sSQL);
                                        if (PEAR::isError($x))
                                                exit;
                                        }
 
-                                       $sSQL = "update search_name_".$sPartition." set";
-                                       $sSQL .= " nameaddress_vector = (nameaddress_vector - ".$aRemove['word_id'].")+".$iKeepID;
-                                       $sSQL .= " where nameaddress_vector @> ARRAY[".$aRemove['word_id']."]";
-                                       $x = $oDB->query($sSQL);
-                                       if (PEAR::isError($x))
-                                       {
-                                               var_dump($x);
-                                               exit;
-                                       }
-
                                        $sSQL = "update location_area_country set";
-                                       $sSQL .= " keywords = (keywords - ".$aRemove['word_id'].")+".$iKeepID;
+                                       $sSQL .= " keywords = array_replace(keywords,".$aRemove['word_id'].",".$iKeepID.")";
                                        $sSQL .= " where keywords @> ARRAY[".$aRemove['word_id']."]";
                                        $x = $oDB->query($sSQL);
                                        if (PEAR::isError($x))
        if ($aResult['index'])
        {
                if (!isset($aResult['index-instances'])) $aResult['index-instances'] = 1;
-               passthru(CONST_BasePath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -t '.$aResult['index-instances'].' -r '.$aResult['index-rank']);
+               passthru(CONST_BasePath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'].' -t '.$aResult['index-instances'].' -r '.$aResult['index-rank']);
        }
 
        if ($aResult['import-osmosis'] || $aResult['import-osmosis-all'])
                $sCMDDownload = $sOsmosisCMD.' --read-replication-interval workingDirectory='.$sOsmosisConfigDirectory.' --simplify-change --write-xml-change '.$sImportFile;
                $sCMDCheckReplicationLag = $sOsmosisCMD.' -q --read-replication-lag workingDirectory='.$sOsmosisConfigDirectory;
                $sCMDImport = $sOsm2pgsqlCmd.' '.$sImportFile;
-               $sCMDIndex = $sBasePath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'];
+               $sCMDIndex = $sBasePath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'];
                if (!$aResult['no-npi']) {
                        $sCMDIndex .= '-F ';
                }
                        // Index file
                        if (!isset($aResult['index-instances']))
                        {
-                               if (getLoadAverage() < 15)
+                               if (getLoadAverage() < 24)
                                        $iIndexInstances = 2;
                                else
                                        $iIndexInstances = 1;