]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge remote-tracking branch 'upstream/master'
authorSarah Hoffmann <lonvia@denofr.de>
Wed, 5 Feb 2014 19:19:05 +0000 (20:19 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Wed, 5 Feb 2014 19:19:05 +0000 (20:19 +0100)
Conflicts:
lib/init-website.php

lib/Geocode.php
lib/init-website.php
lib/lib.php
lib/template/address-xml.php
munin/nominatim_importlag
website/search.php
website/status.php

index eda692b00d792d695db4d020edb34078dc3af444..c464aeedae82fd417a209ff0a2a4e5b153bc8aad 100644 (file)
@@ -20,6 +20,7 @@
                protected $iLimit = 20;
                protected $iFinalLimit = 10;
                protected $iOffset = 0;
+               protected $bFallback = false;
 
                protected $aCountryCodes = false;
                protected $aNearPoint = false;
                        $this->iOffset = $iOffset;
                }
 
+               function setFallback($bFallback = true)
+               {
+                       $this->bFallback = (bool)$bFallback;
+               }
+
                function setExcludedPlaceIDs($a)
                {
                        // TODO: force to int
                {
                        $this->sQuery = false;
 
+                       // Reset
+                       $this->iMinAddressRank = 0;
+                       $this->iMaxAddressRank = 30;
+                       $this->aAddressRankList = array();
+
                        $this->aStructuredQuery = array();
                        $this->sAllowedTypesSQLList = '';
 
                                        $sAllowedTypesSQLList = '(\'place\',\'boundary\')';
                                }
                        }
+               }
+
+               function fallbackStructuredQuery()
+               {
+                       if (!$this->aStructuredQuery) return false;
+
+                       $aParams = $this->aStructuredQuery;
+
+                       if (sizeof($aParams) == 1) return false;
+
+                       $aOrderToFallback = array('postalcode', 'street', 'city', 'county', 'state');
+
+                       foreach($aOrderToFallback as $sType)
+                       {
+                               if (isset($aParams[$sType]))
+                               {
+                                       unset($aParams[$sType]);
+                                       $this->setStructuredQuery(@$aParams['amenity'], @$aParams['street'], @$aParams['city'], @$aParams['county'], @$aParams['state'], @$aParams['country'], @$aParams['postalcode']);
+                                       return true;
+                               }
+                       }
 
+                       return false;
                }
 
                function getDetails($aPlaceIDs)
                        // No results? Done
                        if (!sizeof($aSearchResults))
                        {
+                               if ($this->bFallback)
+                               {
+                                       if ($this->fallbackStructuredQuery())
+                                       {
+                                               return $this->lookup();
+                                       }
+                               }
+
                                return array();
                        }
 
index 4d1c2c7029a1cdc00b999b5c0c748eb27a517cd7..013aee4b4a1c07daf07dde2389baff9f85069a11 100644 (file)
@@ -13,5 +13,4 @@
        }
        if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') exit;
 
-
     header('Content-type: text/html; charset=utf-8');
index e569aa8b53e299a4c2f4d3b618b3525d8200d618..482e95981cc04b7aab021eb82e979c9e950727a9 100644 (file)
                        $sSQL .= ' ORDER BY ST_distance('.$sPointSQL.', geometry) ASC limit 1';
                        //var_dump($sSQL);
                        $aPlace = $oDB->getRow($sSQL);
-                       $iPlaceID = $aPlace['place_id'];
-                       if (PEAR::IsError($iPlaceID))
+                       if (PEAR::IsError($aPlace))
                        {
-                               var_Dump($sSQL, $iPlaceID);
+                               var_Dump($sSQL, $aPlace);
                                exit;
                        }
+                       $iPlaceID = $aPlace['place_id'];
                }
 
                // The point we found might be too small - use the address to find what it is a child of
index 0747844a67ac6db8a8306f0dc74152c3b36d6364..9eeb3b778a6c5737d76a49ee33cfd3455fa47081 100644 (file)
@@ -22,7 +22,8 @@
        {
                echo "<result";
                if ($aPlace['place_id']) echo ' place_id="'.$aPlace['place_id'].'"';
-               if ($aPlace['osm_type'] && $aPlace['osm_id']) echo ' osm_type="'.($aPlace['osm_type']=='N'?'node':($aPlace['osm_type']=='W'?'way':'relation')).'"'.' osm_id="'.$aPlace['osm_id'].'"';
+               $sOSMType = ($aPlace['osm_type'] == 'N'?'node':($aPlace['osm_type'] == 'W'?'way':($aPlace['osm_type'] == 'R'?'relation':'')));
+               if ($sOSMType) echo ' osm_type="'.$sOSMType.'"'.' osm_id="'.$aPlace['osm_id'].'"';
                if ($aPlace['ref']) echo ' ref="'.htmlspecialchars($aPlace['ref']).'"';
                if (isset($aPlace['lat'])) echo ' lat="'.htmlspecialchars($aPlace['lat']).'"';
                if (isset($aPlace['lon'])) echo ' lon="'.htmlspecialchars($aPlace['lon']).'"';
index 9f40131194aa2ee18e6a1fd97b9d08fd0f0dc1d6..0960ff5a39c170ee08badb0979533c6cc14fc9af 100755 (executable)
@@ -5,26 +5,42 @@
 # Can be configured through libpq environment variables, for example
 # PGUSER, PGDATABASE, etc. See man page of psql for more information
 #
-# Parameters: 
+# To configure munin for a default installation, add these lines to
+# the file /etc/munin/plugin-conf.d/munin-node or in any file in the
+# directory /etc/munin/plugin-conf.d/
+#
+# [nominatim_*]
+# user www-data
+# env.PGUSER www-data
+# env.PGPORT 5432
+# env.PGDATABASE nominatim
+# env.age_warning 21600
+# env.age_critical 86400
+
+# Parameters:
 #
 #       config   (required)
 #       autoconf (optional - used by munin-config)
 #
+
+. $MUNIN_LIBDIR/plugins/plugin.sh
+
 if [ "$1" = "config" ]; then
-        echo 'graph_title Data import lag' 
-        echo 'graph_args --base 1000 -l 0' 
-        echo 'graph_vlabel minutes' 
-        echo 'graph_category nominatim' 
-        echo 'age.label DB import age' 
-        echo 'age.type GAUGE' 
+
+        echo 'graph_title Data import lag'
+        echo 'graph_args --base 1000 -l 0'
+        echo 'graph_vlabel minutes'
+        echo 'graph_category nominatim'
+        echo 'age.label DB import age'
+        echo 'age.type GAUGE'
         echo 'age.cdef age,60,/'
+        print_warning age
+        print_critical age
         exit 0
 fi
+
 
 delay=`psql -c "copy (select extract(epoch from timezone('utc', now())-lastimportdate)::int from import_status) to stdout"`
+
+
 echo "age.value $delay"
index 29c87320f7b11e87be427d7d7d19e8a9bc1659d7..e85c33697fa66554a7bb532aadf3ff3001cadedb 100755 (executable)
@@ -36,6 +36,8 @@
                if (isset($aParams['limit'])) $oGeocode->setLimit((int)$aParams['limit']);
                if (isset($aParams['offset'])) $oGeocode->setOffset((int)$aParams['offset']);
 
+               if (isset($aParams['fallback'])) $oGeocode->setFallback((int)$aParams['fallback']);
+
                // List of excluded Place IDs - used for more acurate pageing
                if (isset($aParams['exclude_place_ids']) && $aParams['exclude_place_ids'])
                {
index c9d872d0395e67ae2d5736e439d5565fe02f89c8..a876f999ffc456b820568044df4e1c03bc2a44f7 100644 (file)
@@ -3,24 +3,39 @@
 
        require_once(dirname(dirname(__FILE__)).'/lib/init-website.php');
 
+       function statusError($sMsg)
+       {
+               header("HTTP/1.0 500 Internal Server Error");
+               echo "ERROR: ".$sMsg;
+               exit;
+       }
+
        $oDB =& getDB();
        if (!$oDB || PEAR::isError($oDB))
        {
-               echo "ERROR: No database";
-               exit;
+               statusError("No database");
+       }
+
+       $sStandardWord = $oDB->getOne("select make_standard_name('a')");
+       if (PEAR::isError($sStandardWord))
+       {
+               statusError("Module failed");
+       }
+       if ($sStandardWord != 'a')
+       {
+               statusError("Module call failed");
        }
 
        $iWordID = $oDB->getOne("select word_id,word_token, word, class, type, country_code, operator, search_name_count from word where word_token in (' a')");
        if (PEAR::isError($iWordID))
        {
-               echo "ERROR: Query failed";
-               exit;
+               statusError("Query failed");
        }
        if (!$iWordID)
        {
-               echo "ERROR: No value";
-               exit;
+               statusError("No value");
        }
+
        echo "OK";
        exit;