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();
}
}
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') exit;
-
header('Content-type: text/html; charset=utf-8');
$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
{
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']).'"';
# 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"
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'])
{
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;