]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/admin/warm.php
replace NOMINATIM_PHRASE_CONFIG with command line option
[nominatim.git] / lib-php / admin / warm.php
1 <?php
2 @define('CONST_LibDir', dirname(dirname(__FILE__)));
3
4 require_once(CONST_LibDir.'/init-cmd.php');
5 require_once(CONST_LibDir.'/log.php');
6 require_once(CONST_LibDir.'/PlaceLookup.php');
7 require_once(CONST_LibDir.'/ReverseGeocode.php');
8
9 ini_set('memory_limit', '800M');
10
11 $aCMDOptions = array(
12                 'Tools to warm nominatim db',
13                 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
14                 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
15                 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
16                 array('reverse-only', '', 0, 1, 0, 0, 'bool', 'Warm reverse only'),
17                 array('search-only', '', 0, 1, 0, 0, 'bool', 'Warm search only'),
18                 array('project-dir', '', 0, 1, 1, 1, 'realpath', 'Base directory of the Nominatim installation (default: .)'),
19                );
20 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true);
21
22 loadSettings($aCMDResult['project-dir'] ?? getcwd());
23
24 @define('CONST_Database_DSN', getSetting('DATABASE_DSN'));
25 @define('CONST_Default_Language', getSetting('DEFAULT_LANGUAGE', false));
26 @define('CONST_Log_DB', getSettingBool('LOG_DB'));
27 @define('CONST_Log_File', getSetting('LOG_FILE', false));
28 @define('CONST_NoAccessControl', getSettingBool('CORS_NOACCESSCONTROL'));
29 @define('CONST_Places_Max_ID_count', getSetting('LOOKUP_MAX_COUNT'));
30 @define('CONST_PolygonOutput_MaximumTypes', getSetting('POLYGON_OUTPUT_MAX_TYPES'));
31 @define('CONST_Search_BatchMode', getSettingBool('SEARCH_BATCH_MODE'));
32 @define('CONST_Search_NameOnlySearchFrequencyThreshold', getSetting('SEARCH_NAME_ONLY_THRESHOLD'));
33 @define('CONST_Use_US_Tiger_Data', getSettingBool('USE_US_TIGER_DATA'));
34 @define('CONST_MapIcon_URL', getSetting('MAPICON_URL', false));
35 @define('CONST_TokenizerDir', CONST_InstallDir.'/tokenizer');
36
37 require_once(CONST_LibDir.'/Geocode.php');
38
39 $oDB = new Nominatim\DB();
40 $oDB->connect();
41
42 $bVerbose = $aResult['verbose'];
43
44 function print_results($aResults, $bVerbose)
45 {
46     if ($bVerbose) {
47         if ($aResults && count($aResults)) {
48             echo $aResults[0]['langaddress']."\n";
49         } else {
50             echo "<not found>\n";
51         }
52     } else {
53         echo '.';
54     }
55 }
56
57 if (!$aResult['search-only']) {
58     $oReverseGeocode = new Nominatim\ReverseGeocode($oDB);
59     $oReverseGeocode->setZoom(20);
60     $oPlaceLookup = new Nominatim\PlaceLookup($oDB);
61     $oPlaceLookup->setIncludeAddressDetails(true);
62     $oPlaceLookup->setLanguagePreference(array('en'));
63
64     echo 'Warm reverse: ';
65     if ($bVerbose) {
66         echo "\n";
67     }
68     for ($i = 0; $i < 1000; $i++) {
69         $fLat = rand(-9000, 9000) / 100;
70         $fLon = rand(-18000, 18000) / 100;
71         if ($bVerbose) {
72             echo "$fLat, $fLon = ";
73         }
74
75         $oLookup = $oReverseGeocode->lookup($fLat, $fLon);
76         $aSearchResults = $oLookup ? $oPlaceLookup->lookup(array($oLookup->iId => $oLookup)) : null;
77         print_results($aSearchResults, $bVerbose);
78     }
79     echo "\n";
80 }
81
82 if (!$aResult['reverse-only']) {
83     $oGeocode = new Nominatim\Geocode($oDB);
84
85     echo 'Warm search: ';
86     if ($bVerbose) {
87         echo "\n";
88     }
89     $sSQL = 'SELECT word FROM word WHERE word is not null ORDER BY search_name_count DESC LIMIT 1000';
90     foreach ($oDB->getCol($sSQL) as $sWord) {
91         if ($bVerbose) {
92             echo "$sWord = ";
93         }
94
95         $oGeocode->setLanguagePreference(array('en'));
96         $oGeocode->setQuery($sWord);
97         $aSearchResults = $oGeocode->lookup();
98         print_results($aSearchResults, $bVerbose);
99     }
100     echo "\n";
101 }