]> git.openstreetmap.org Git - nominatim.git/blob - utils/warm.php
replace database abstraction DB with PDO
[nominatim.git] / utils / warm.php
1 <?php
2
3 require_once(CONST_BasePath.'/lib/init-cmd.php');
4 ini_set('memory_limit', '800M');
5
6 $aCMDOptions = array(
7                 'Tools to warm nominatim db',
8                 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
9                 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
10                 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
11                 array('reverse-only', '', 0, 1, 0, 0, 'bool', 'Warm reverse only'),
12                 array('search-only', '', 0, 1, 0, 0, 'bool', 'Warm search only'),
13                );
14 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true);
15
16 require_once(CONST_BasePath.'/lib/log.php');
17 require_once(CONST_BasePath.'/lib/Geocode.php');
18 require_once(CONST_BasePath.'/lib/PlaceLookup.php');
19 require_once(CONST_BasePath.'/lib/ReverseGeocode.php');
20
21 $oDB = new Nominatim\DB();
22 $oDB->connect();
23
24 $bVerbose = $aResult['verbose'];
25
26 if (!$aResult['search-only']) {
27     $oReverseGeocode = new Nominatim\ReverseGeocode($oDB);
28     $oReverseGeocode->setZoom(20);
29     $oPlaceLookup = new Nominatim\PlaceLookup($oDB);
30     $oPlaceLookup->setIncludeAddressDetails(true);
31     $oPlaceLookup->setLanguagePreference(array('en'));
32
33     echo 'Warm reverse: ';
34     if ($bVerbose) echo "\n";
35     for ($i = 0; $i < 1000; $i++) {
36         $fLat = rand(-9000, 9000) / 100;
37         $fLon = rand(-18000, 18000) / 100;
38         if ($bVerbose) echo "$fLat, $fLon = ";
39         $oLookup = $oReverseGeocode->lookup($fLat, $fLon);
40         if ($oLookup) {
41             $aDetails = $oPlaceLookup->lookup(array($oLookup->iId => $oLookup));
42             if ($bVerbose) echo $aDetails['langaddress']."\n";
43         } else {
44             echo '.';
45         }
46     }
47     echo "\n";
48 }
49
50 if (!$aResult['reverse-only']) {
51     $oGeocode = new Nominatim\Geocode($oDB);
52
53     echo 'Warm search: ';
54     if ($bVerbose) echo "\n";
55     $sSQL = 'select word from word where word is not null order by search_name_count desc limit 1000';
56     foreach ($oDB->getCol($sSQL) as $sWord) {
57         if ($bVerbose) echo "$sWord = ";
58         $oGeocode->setLanguagePreference(array('en'));
59         $oGeocode->setQuery($sWord);
60         $aSearchResults = $oGeocode->lookup();
61         if ($bVerbose) echo $aSearchResults[0]['langaddress']."\n";
62         else echo '.';
63     }
64 }