]> git.openstreetmap.org Git - nominatim.git/blob - utils/setup.php
Make rank assignments configurable
[nominatim.git] / utils / setup.php
1 #!@PHP_BIN@ -Cq
2 <?php
3
4 require_once(dirname(dirname(__FILE__)).'/settings/settings.php');
5 require_once(CONST_BasePath.'/lib/init-cmd.php');
6 // ->indirect via init-cmd.php->/lib/cmd.php                for runWithEnv, getCmdOpt
7 // ->indirect via init-cmd.php->/lib/init.php->db.php       for &getDB()
8
9 require_once(CONST_BasePath.'/lib/setup/SetupClass.php');
10 require_once(CONST_BasePath.'/lib/setup_functions.php');
11 ini_set('memory_limit', '800M');
12
13 use Nominatim\Setup\SetupFunctions as SetupFunctions;
14
15 // (long-opt, short-opt, min-occurs, max-occurs, num-arguments, num-arguments, type, help)
16 $aCMDOptions
17 = array(
18    'Create and setup nominatim search system',
19    array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
20    array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
21    array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
22
23    array('osm-file', '', 0, 1, 1, 1, 'realpath', 'File to import'),
24    array('threads', '', 0, 1, 1, 1, 'int', 'Number of threads (where possible)'),
25
26    array('all', '', 0, 1, 0, 0, 'bool', 'Do the complete process'),
27
28    array('create-db', '', 0, 1, 0, 0, 'bool', 'Create nominatim db'),
29    array('setup-db', '', 0, 1, 0, 0, 'bool', 'Build a blank nominatim db'),
30    array('import-data', '', 0, 1, 0, 0, 'bool', 'Import a osm file'),
31    array('osm2pgsql-cache', '', 0, 1, 1, 1, 'int', 'Cache size used by osm2pgsql'),
32    array('reverse-only', '', 0, 1, 0, 0, 'bool', 'Do not create search tables and indexes'),
33    array('create-functions', '', 0, 1, 0, 0, 'bool', 'Create functions'),
34    array('enable-diff-updates', '', 0, 1, 0, 0, 'bool', 'Turn on the code required to make diff updates work'),
35    array('enable-debug-statements', '', 0, 1, 0, 0, 'bool', 'Include debug warning statements in pgsql commands'),
36    array('ignore-errors', '', 0, 1, 0, 0, 'bool', 'Continue import even when errors in SQL are present (EXPERT)'),
37    array('create-tables', '', 0, 1, 0, 0, 'bool', 'Create main tables'),
38    array('create-partition-tables', '', 0, 1, 0, 0, 'bool', 'Create required partition tables'),
39    array('create-partition-functions', '', 0, 1, 0, 0, 'bool', 'Create required partition triggers'),
40    array('no-partitions', '', 0, 1, 0, 0, 'bool', 'Do not partition search indices (speeds up import of single country extracts)'),
41    array('import-wikipedia-articles', '', 0, 1, 0, 0, 'bool', 'Import wikipedia article dump'),
42    array('load-data', '', 0, 1, 0, 0, 'bool', 'Copy data to live tables from import table'),
43    array('disable-token-precalc', '', 0, 1, 0, 0, 'bool', 'Disable name precalculation (EXPERT)'),
44    array('import-tiger-data', '', 0, 1, 0, 0, 'bool', 'Import tiger data (not included in \'all\')'),
45    array('calculate-postcodes', '', 0, 1, 0, 0, 'bool', 'Calculate postcode centroids'),
46    array('osmosis-init', '', 0, 1, 0, 0, 'bool', 'Generate default osmosis configuration'),
47    array('index', '', 0, 1, 0, 0, 'bool', 'Index the data'),
48    array('index-noanalyse', '', 0, 1, 0, 0, 'bool', 'Do not perform analyse operations during index (EXPERT)'),
49    array('create-search-indices', '', 0, 1, 0, 0, 'bool', 'Create additional indices required for search and update'),
50    array('create-country-names', '', 0, 1, 0, 0, 'bool', 'Create default list of searchable country names'),
51    array('drop', '', 0, 1, 0, 0, 'bool', 'Drop tables needed for updates, making the database readonly (EXPERIMENTAL)'),
52   );
53
54 // $aCMDOptions passed to getCmdOpt by reference
55 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
56
57 $bDidSomething = false;
58
59 //*******************************************************
60 // Making some sanity check:
61 // Check if osm-file is set and points to a valid file
62 if ($aCMDResult['import-data'] || $aCMDResult['all']) {
63     // to remain in /lib/setup_functions.php function
64     checkInFile($aCMDResult['osm-file']);
65 }
66
67 // osmosis init is no longer supported
68 if ($aCMDResult['osmosis-init']) {
69     $bDidSomething = true;
70     echo "Command 'osmosis-init' no longer available, please use utils/update.php --init-updates.\n";
71 }
72
73 // ******************************************************
74 // instantiate Setup class
75 $oSetup = new SetupFunctions($aCMDResult);
76
77 // *******************************************************
78 // go through complete process if 'all' is selected or start selected functions
79 if ($aCMDResult['create-db'] || $aCMDResult['all']) {
80     $bDidSomething = true;
81     $oSetup->createDB();
82 }
83
84 $oSetup->connect();
85
86 if ($aCMDResult['setup-db'] || $aCMDResult['all']) {
87     $bDidSomething = true;
88     $oSetup->setupDB();
89 }
90
91 // Try accessing the C module, so we know early if something is wrong
92 if (!checkModulePresence()) {
93     fail('error loading nominatim.so module');
94 }
95
96 if ($aCMDResult['import-data'] || $aCMDResult['all']) {
97     $bDidSomething = true;
98     $oSetup->importData($aCMDResult['osm-file']);
99 }
100
101 if ($aCMDResult['create-functions'] || $aCMDResult['all']) {
102     $bDidSomething = true;
103     $oSetup->createFunctions();
104 }
105
106 if ($aCMDResult['create-tables'] || $aCMDResult['all']) {
107     $bDidSomething = true;
108     $oSetup->createTables($aCMDResult['reverse-only']);
109     $oSetup->createFunctions();
110 }
111
112 if ($aCMDResult['create-partition-tables'] || $aCMDResult['all']) {
113     $bDidSomething = true;
114     $oSetup->createPartitionTables();
115 }
116
117 if ($aCMDResult['create-partition-functions'] || $aCMDResult['all']) {
118     $bDidSomething = true;
119     $oSetup->createPartitionFunctions();
120 }
121
122 if ($aCMDResult['import-wikipedia-articles'] || $aCMDResult['all']) {
123     $bDidSomething = true;
124     $oSetup->importWikipediaArticles();
125 }
126
127 if ($aCMDResult['load-data'] || $aCMDResult['all']) {
128     $bDidSomething = true;
129     $oSetup->loadData($aCMDResult['disable-token-precalc']);
130 }
131
132 if ($aCMDResult['import-tiger-data']) {
133     $bDidSomething = true;
134     $oSetup->importTigerData();
135 }
136
137 if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) {
138     $bDidSomething = true;
139     $oSetup->calculatePostcodes($aCMDResult['all']);
140 }
141
142 if ($aCMDResult['index'] || $aCMDResult['all']) {
143     $bDidSomething = true;
144     $oSetup->index($aCMDResult['index-noanalyse']);
145 }
146
147 if ($aCMDResult['create-search-indices'] || $aCMDResult['all']) {
148     $bDidSomething = true;
149     $oSetup->createSearchIndices();
150 }
151
152 if ($aCMDResult['create-country-names'] || $aCMDResult['all']) {
153     $bDidSomething = true;
154     $oSetup->createCountryNames($aCMDResult);
155 }
156
157 if ($aCMDResult['drop']) {
158     $bDidSomething = true;
159     $oSetup->drop($aCMDResult);
160 }
161
162 // ******************************************************
163 // If we did something, repeat the warnings
164 if (!$bDidSomething) {
165     showUsage($aCMDOptions, true);
166 } else {
167     echo "Summary of warnings:\n\n";
168     repeatWarnings();
169     echo "\n";
170     info('Setup finished.');
171 }