]> git.openstreetmap.org Git - nominatim.git/blobdiff - website/details.php
Declare return type of testcase setUp method
[nominatim.git] / website / details.php
index b9818bbf74ba3bae640d46f84713c4d2c17b4049..6f7c807d88d58890ec235ec0f519833a7c2ca0c1 100644 (file)
@@ -30,14 +30,31 @@ $oDB->connect();
 
 $sLanguagePrefArraySQL = $oDB->getArraySQL($oDB->getDBQuotedList($aLangPrefOrder));
 
+if ($sOutputFormat == 'html' && !$sPlaceId && !$sOsmType) {
+    include(CONST_BasePath.'/lib/template/details-index-html.php');
+    exit;
+}
+
 if ($sOsmType && $iOsmId > 0) {
     $sSQL = 'SELECT place_id FROM placex WHERE osm_type = :type AND osm_id = :id';
+    $aSQLParams = array(':type' => $sOsmType, ':id' => $iOsmId);
     // osm_type and osm_id are not unique enough
     if ($sClass) {
-        $sSQL .= " AND class='".$sClass."'";
+        $sSQL .= ' AND class= :class';
+        $aSQLParams[':class'] = $sClass;
     }
     $sSQL .= ' ORDER BY class ASC';
-    $sPlaceId = $oDB->getOne($sSQL, array(':type' => $sOsmType, ':id' => $iOsmId));
+    $sPlaceId = $oDB->getOne($sSQL, $aSQLParams);
+
+
+    // Nothing? Maybe it's an interpolation.
+    // XXX Simply returns the first parent street it finds. It should
+    //     get a house number and get the right interpolation.
+    if (!$sPlaceId && $sOsmType == 'W' && (!$sClass || $sClass == 'place')) {
+        $sSQL = 'SELECT place_id FROM location_property_osmline'
+                .' WHERE osm_id = :id LIMIT 1';
+        $sPlaceId = $oDB->getOne($sSQL, array(':id' => $iOsmId));
+    }
 
     // Be nice about our error messages for broken geometry
 
@@ -220,11 +237,17 @@ if ($bIncludeKeywords) {
     $aPlaceSearchName = $oDB->getRow($sSQL);
 
     if (!empty($aPlaceSearchName)) {
-        $sSQL = 'SELECT * FROM word WHERE word_id in ('.substr($aPlaceSearchName['name_vector'], 1, -1).')';
-        $aPlaceSearchNameKeywords = $oDB->getAll($sSQL);
+        $sWordIds = substr($aPlaceSearchName['name_vector'], 1, -1);
+        if (!empty($sWordIds)) {
+            $sSQL = 'SELECT * FROM word WHERE word_id in ('.$sWordIds.')';
+            $aPlaceSearchNameKeywords = $oDB->getAll($sSQL);
+        }
 
-        $sSQL = 'SELECT * FROM word WHERE word_id in ('.substr($aPlaceSearchName['nameaddress_vector'], 1, -1).')';
-        $aPlaceSearchAddressKeywords = $oDB->getAll($sSQL);
+        $sWordIds = substr($aPlaceSearchName['nameaddress_vector'], 1, -1);
+        if (!empty($sWordIds)) {
+            $sSQL = 'SELECT * FROM word WHERE word_id in ('.$sWordIds.')';
+            $aPlaceSearchAddressKeywords = $oDB->getAll($sSQL);
+        }
     }
 }