]> git.openstreetmap.org Git - nominatim.git/blob - utils/warm.php
utils/check_import_finished: skip some checks when setup ran with --drop
[nominatim.git] / utils / warm.php
1 <?php
2
3 require_once(CONST_LibDir.'/init-cmd.php');
4 require_once(CONST_LibDir.'/log.php');
5 require_once(CONST_LibDir.'/Geocode.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 $oDB = new Nominatim\DB();
25 $oDB->connect();
26
27 $bVerbose = $aResult['verbose'];
28
29 function print_results($aResults, $bVerbose)
30 {
31     if ($bVerbose) {
32         if ($aResults && count($aResults)) {
33             echo $aResults[0]['langaddress']."\n";
34         } else {
35             echo "<not found>\n";
36         }
37     } else {
38         echo '.';
39     }
40 }
41
42 if (!$aResult['search-only']) {
43     $oReverseGeocode = new Nominatim\ReverseGeocode($oDB);
44     $oReverseGeocode->setZoom(20);
45     $oPlaceLookup = new Nominatim\PlaceLookup($oDB);
46     $oPlaceLookup->setIncludeAddressDetails(true);
47     $oPlaceLookup->setLanguagePreference(array('en'));
48
49     echo 'Warm reverse: ';
50     if ($bVerbose) echo "\n";
51     for ($i = 0; $i < 1000; $i++) {
52         $fLat = rand(-9000, 9000) / 100;
53         $fLon = rand(-18000, 18000) / 100;
54         if ($bVerbose) echo "$fLat, $fLon = ";
55
56         $oLookup = $oReverseGeocode->lookup($fLat, $fLon);
57         $aSearchResults = $oLookup ? $oPlaceLookup->lookup(array($oLookup->iId => $oLookup)) : null;
58         print_results($aSearchResults, $bVerbose);
59     }
60     echo "\n";
61 }
62
63 if (!$aResult['reverse-only']) {
64     $oGeocode = new Nominatim\Geocode($oDB);
65
66     echo 'Warm search: ';
67     if ($bVerbose) echo "\n";
68     $sSQL = 'SELECT word FROM word WHERE word is not null ORDER BY search_name_count DESC LIMIT 1000';
69     foreach ($oDB->getCol($sSQL) as $sWord) {
70         if ($bVerbose) echo "$sWord = ";
71
72         $oGeocode->setLanguagePreference(array('en'));
73         $oGeocode->setQuery($sWord);
74         $aSearchResults = $oGeocode->lookup();
75         print_results($aSearchResults, $bVerbose);
76     }
77     echo "\n";
78 }