]> git.openstreetmap.org Git - nominatim.git/blobdiff - utils/setup.php
use calculated_country_code for postcodes
[nominatim.git] / utils / setup.php
index 1db725c466f23b8c826069d2a662cc021ea9d5a6..9ac9b097c9b162abf63c8f7a71e7d550780e9261 100755 (executable)
 
        if ($aCMDResult['load-data'] || $aCMDResult['all'])
        {
-               echo "Load Data\n";
+               echo "Drop old Data\n";
                $bDidSomething = true;
 
                $oDB =& getDB();
                        echo '.';
                }
 
+               // used by getorcreate_word_id to ignore frequent partial words
+               if (!pg_query($oDB->connection, 'CREATE OR REPLACE FUNCTION get_maxwordfreq() RETURNS integer AS $$ SELECT '.CONST_Max_Word_Frequency.' as maxwordfreq; $$ LANGUAGE SQL IMMUTABLE')) fail(pg_last_error($oDB->connection));
+               echo ".\n";
+
                // pre-create the word list
                if (!$aCMDResult['disable-token-precalc'])
                {
-                       if (!pg_query($oDB->connection, 'select count(make_keywords(v)) from (select distinct svals(name) as v from place) as w where v is not null;')) fail(pg_last_error($oDB->connection));
-                       echo '.';
-                       if (!pg_query($oDB->connection, 'select count(make_keywords(v)) from (select distinct postcode as v from place) as w where v is not null;')) fail(pg_last_error($oDB->connection));
-                       echo '.';
-                       if (!pg_query($oDB->connection, 'select count(getorcreate_housenumber_id(v)) from (select distinct housenumber as v from place where housenumber is not null) as w;')) fail(pg_last_error($oDB->connection));
-                       echo '.';
+                       echo "Loading word list\n";
+                       pgsqlRunScriptFile(CONST_BasePath.'/data/words.sql');
                }
 
+               echo "Load Data\n";
                $aDBInstances = array();
                for($i = 0; $i < $iInstances; $i++)
                {
                {
                        $aDBInstances[$i] =& getDB(true);
                        if (!pg_query($aDBInstances[$i]->connection, 'set enable_bitmapscan = off')) fail(pg_last_error($oDB->connection));
-                       $sSQL = 'select count(*) from (select insertLocationRoad(partition, place_id, country_code, geometry) from ';
+                       $sSQL = 'select count(*) from (select insertLocationRoad(partition, place_id, calculated_country_code, geometry) from ';
                        $sSQL .= 'placex where osm_id % '.$iInstances.' = '.$i.' and rank_search between 26 and 27 and class = \'highway\') as x ';
                        if ($aCMDResult['verbose']) echo "$sSQL\n";
                        if (!pg_send_query($aDBInstances[$i]->connection, $sSQL)) fail(pg_last_error($oDB->connection));
                $bDidSomething = true;
                $oDB =& getDB();
                if (!pg_query($oDB->connection, 'DELETE from placex where osm_type=\'P\'')) fail(pg_last_error($oDB->connection));
-               $sSQL = "insert into placex (osm_type,osm_id,class,type,postcode,country_code,geometry) ";
-               $sSQL .= "select 'P',nextval('seq_postcodes'),'place','postcode',postcode,country_code,";
-               $sSQL .= "ST_SetSRID(ST_Point(x,y),4326) as geometry from (select country_code,postcode,";
+               $sSQL = "insert into placex (osm_type,osm_id,class,type,postcode,calculated_country_code,geometry) ";
+               $sSQL .= "select 'P',nextval('seq_postcodes'),'place','postcode',postcode,calculated_country_code,";
+               $sSQL .= "ST_SetSRID(ST_Point(x,y),4326) as geometry from (select calculated_country_code,postcode,";
                $sSQL .= "avg(st_x(st_centroid(geometry))) as x,avg(st_y(st_centroid(geometry))) as y ";
-               $sSQL .= "from placex where postcode is not null group by country_code,postcode) as x";
+               $sSQL .= "from placex where postcode is not null group by calculated_country_code,postcode) as x";
                if (!pg_query($oDB->connection, $sSQL)) fail(pg_last_error($oDB->connection));
 
-               $sSQL = "insert into placex (osm_type,osm_id,class,type,postcode,country_code,geometry) ";
+               $sSQL = "insert into placex (osm_type,osm_id,class,type,postcode,calcuclated_country_code,geometry) ";
                $sSQL .= "select 'P',nextval('seq_postcodes'),'place','postcode',postcode,'us',";
                $sSQL .= "ST_SetSRID(ST_Point(x,y),4326) as geometry from us_postcode";
                if (!pg_query($oDB->connection, $sSQL)) fail(pg_last_error($oDB->connection));
 
                if (!file_exists(CONST_Osmosis_Binary)) fail("please download osmosis");
                if (file_exists(CONST_BasePath.'/settings/configuration.txt')) echo "settings/configuration.txt already exists\n";
-               else passthru(CONST_Osmosis_Binary.' --read-replication-interval-init '.CONST_BasePath.'/settings');
+               else
+               {
+                       passthru(CONST_Osmosis_Binary.' --read-replication-interval-init '.CONST_BasePath.'/settings');
+                       // server layout changed afer license change, fix path to minutely diffs
+                       passthru("sed -i 's:minute-replicate:replication/minute:' ".CONST_BasePath.'/settings/configuration.txt');
+               }
 
                $sDate = $aCMDResult['osmosis-init-date'];
                $aDate = date_parse_from_format("Y-m-d\TH-i", $sDate);