]> git.openstreetmap.org Git - nominatim.git/blob - utils/warm.php
72eac27adf254d0597596a66813bff6539e9a71c
[nominatim.git] / utils / warm.php
1 #!/usr/bin/php -Cq
2 <?php
3
4         require_once(dirname(dirname(__FILE__)).'/settings/settings.php');
5         require_once(CONST_BasePath.'/lib/init-cmd.php');
6         ini_set('memory_limit', '800M');
7
8         $aCMDOptions = array(
9                 "Tools to warm nominatim db",
10                 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
11                 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
12                 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
13                 array('reverse-only', '', 0, 1, 0, 0, 'bool', 'Warm reverse only'),
14                 array('search-only', '', 0, 1, 0, 0, 'bool', 'Warm reverse only'),
15         );
16         getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true);
17
18         require_once(CONST_BasePath.'/lib/log.php');
19         require_once(CONST_BasePath.'/lib/Geocode.php');
20         require_once(CONST_BasePath.'/lib/PlaceLookup.php');
21         require_once(CONST_BasePath.'/lib/ReverseGeocode.php');
22
23         $oDB =& getDB();
24
25         $bVerbose = $aResult['verbose'];
26
27         if (!$aResult['search-only']) {
28
29                 $oReverseGeocode = new ReverseGeocode($oDB);
30                 $oReverseGeocode->setIncludeAddressDetails(true);
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                         $oReverseGeocode->setLanguagePreference(array('en'));
39                         $oReverseGeocode->setLatLon($fLat, $fLon);
40                         $oReverseGeocode->setZoom(20);
41                         $aDetails = $oReverseGeocode->lookup();
42                         if ($bVerbose) echo $aDetails['langaddress']."\n";
43                         else echo ".";
44                 }
45                 echo "\n";
46         }
47
48         if (!$aResult['reverse-only']) {
49
50                 $oGeocode =& new Geocode($oDB);
51
52                 echo "Warm search: ";
53                 if ($bVerbose) echo "\n";
54                 $sSQL = 'select word from word where word is not null order by search_name_count desc limit 1000';
55                 foreach($oDB->getCol($sSQL) as $sWord) {
56                         if ($bVerbose) echo "$sWord = ";
57                         $oGeocode->setLanguagePreference(array('en'));
58                         $oGeocode->setQuery($sWord);
59                         $aSearchResults = $oGeocode->lookup();
60                         if ($bVerbose) echo $aSearchResults[0]['langaddress']."\n";
61                         else echo ".";
62                 }
63         }
64