X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/25db5f271addc4ff5aa2d3b32f1582c48dca3405..1812c89c31b6e163a14144ae05fff34b97634367:/utils/update.php diff --git a/utils/update.php b/utils/update.php index 395f964d..a561aaa3 100755 --- a/utils/update.php +++ b/utils/update.php @@ -253,6 +253,13 @@ 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); @@ -275,15 +282,15 @@ 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)) @@ -293,7 +300,7 @@ } $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)) @@ -303,7 +310,7 @@ } $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)) @@ -315,8 +322,7 @@ 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)) @@ -325,18 +331,8 @@ 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)) @@ -465,7 +461,7 @@ // Index file if (!isset($aResult['index-instances'])) { - if (getLoadAverage() < 18) + if (getLoadAverage() < 24) $iIndexInstances = 2; else $iIndexInstances = 1;