]> git.openstreetmap.org Git - nominatim.git/blob - utils/warm.php
Remove server_compare from list of installed scripts
[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 =& getDB();
22
23 $bVerbose = $aResult['verbose'];
24
25 if (!$aResult['search-only']) {
26     $oReverseGeocode = new Nominatim\ReverseGeocode($oDB);
27     $oReverseGeocode->setZoom(20);
28     $oPlaceLookup = new Nominatim\PlaceLookup($oDB);
29     $oPlaceLookup->setIncludeAddressDetails(true);
30     $oPlaceLookup->setLanguagePreference(array('en'));
31
32     echo 'Warm reverse: ';
33     if ($bVerbose) echo "\n";
34     for ($i = 0; $i < 1000; $i++) {
35         $fLat = rand(-9000, 9000) / 100;
36         $fLon = rand(-18000, 18000) / 100;
37         if ($bVerbose) echo "$fLat, $fLon = ";
38         $aLookup = $oReverseGeocode->lookup($fLat, $fLon);
39         if ($aLookup && $aLookup['place_id']) {
40             $aDetails = $oPlaceLookup->lookup(
41                 (int)$aLookup['place_id'],
42                 $aLookup['type'],
43                 $aLookup['fraction']
44             );
45             if ($bVerbose) echo $aDetails['langaddress']."\n";
46         } else {
47             echo '.';
48         }
49     }
50     echo "\n";
51 }
52
53 if (!$aResult['reverse-only']) {
54     $oGeocode = new Nominatim\Geocode($oDB);
55
56     echo 'Warm search: ';
57     if ($bVerbose) echo "\n";
58     $sSQL = 'select word from word where word is not null order by search_name_count desc limit 1000';
59     foreach ($oDB->getCol($sSQL) as $sWord) {
60         if ($bVerbose) echo "$sWord = ";
61         $oGeocode->setLanguagePreference(array('en'));
62         $oGeocode->setQuery($sWord);
63         $aSearchResults = $oGeocode->lookup();
64         if ($bVerbose) echo $aSearchResults[0]['langaddress']."\n";
65         else echo '.';
66     }
67 }