]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge remote-tracking branch 'upstream/master'
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 9 Feb 2020 20:19:37 +0000 (21:19 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 9 Feb 2020 20:19:37 +0000 (21:19 +0100)
lib/output.php
lib/setup/SetupClass.php
lib/template/address-html.php
lib/template/search-html.php
test/php/Nominatim/OutputTest.php [new file with mode: 0644]
website/details.php

index 9d4b7502c855044c6859bae36f1d291897ab20c7..823a6631e08cfeab2b134d803784cf77beb985d8 100644 (file)
@@ -12,6 +12,8 @@ function formatOSMType($sType, $bIncludeExternal = true)
     if ($sType == 'T') return 'way';
     if ($sType == 'I') return 'way';
 
+    // not handled: P, L
+
     return '';
 }
 
@@ -33,20 +35,39 @@ function wikipediaLink($aFeature)
     return '';
 }
 
-function detailsLink($aFeature, $sTitle = false)
+function detailsLink($aFeature, $sTitle = false, $sExtraProperties = false)
 {
     if (!$aFeature['place_id']) return '';
 
-    return '<a href="details.php?place_id='.$aFeature['place_id'].'">'.($sTitle?$sTitle:$aFeature['place_id']).'</a>';
+    $sHtml = '<a ';
+    if ($sExtraProperties) {
+        $sHtml .= $sExtraProperties.' ';
+    }
+
+    $sHtml .= 'href="details.php?place_id='.$aFeature['place_id'].'">'.($sTitle?$sTitle:$aFeature['place_id']).'</a>';
+
+    return $sHtml;
 }
 
-function detailsPermaLink($aFeature, $sRefText = false)
+function detailsPermaLink($aFeature, $sRefText = false, $sExtraProperties = false)
 {
     $sOSMType = formatOSMType($aFeature['osm_type'], false);
 
     if ($sOSMType) {
-        $sLabel = $sRefText ? $sRefText : $sOSMType.' '.$aFeature['osm_id'];
-        return '<a href="details.php?osmtype='.$aFeature['osm_type'].'&osmid='.$aFeature['osm_id'].'&class='.$aFeature['class'].'">'.$sLabel.'</a>';
+        $sHtml = '<a ';
+        if ($sExtraProperties) {
+            $sHtml .= $sExtraProperties.' ';
+        }
+        $sHtml .= 'href="details.php?osmtype='.$aFeature['osm_type']
+                  .'&osmid='.$aFeature['osm_id'].'&class='.$aFeature['class'].'">';
+
+        if ($sRefText) {
+            $sHtml .= $sRefText.'</a>';
+        } else {
+            $sHtml .= $sOSMType.' '.$aFeature['osm_id'].'</a>';
+        }
+
+        return $sHtml;
     }
-    return '';
+    return detailsLink($aFeature, $sRefText, $sExtraProperties);
 }
index 34ece8e0f7567d327793a002782c320fb2bcebca..100e384744d42f03f0342104c53017e7053c99cd 100755 (executable)
@@ -566,6 +566,15 @@ class SetupFunctions
     {
         info('Create Search indices');
 
+        $sSQL = 'SELECT relname FROM pg_class, pg_index ';
+        $sSQL .= 'WHERE pg_index.indisvalid = false AND pg_index.indexrelid = pg_class.oid';
+        $aInvalidIndices = $this->oDB->getCol($sSQL);
+
+        foreach ($aInvalidIndices as $sIndexName) {
+            info("Cleaning up invalid index $sIndexName");
+            $this->oDB->exec("DROP INDEX $sIndexName;");
+        }
+
         $sTemplate = file_get_contents(CONST_BasePath.'/sql/indices.src.sql');
         if (!$this->dbReverseOnly()) {
             $sTemplate .= file_get_contents(CONST_BasePath.'/sql/indices_search.src.sql');
index 9b0984289c021060ce48389956e8d4dd9b53c2ef..5be714d3c3bb2453ca4c2a2665b632adeb3a1ffd 100644 (file)
@@ -85,7 +85,7 @@
             else
                 echo ' <span class="type">('.ucwords(str_replace('_',' ',$aResult['type'])).')</span>';
             echo '<p>'.$aResult['lat'].','.$aResult['lon'].'</p>';
-            echo ' <a class="btn btn-default btn-xs details" href="details.php?osmtype='.$aResult['osm_type'].'&osmid='.$aResult['osm_id'].'&class='.$aResult['class'].'">details</a>';
+            echo detailsPermaLink($aResult, 'details', 'class="btn btn-default btn-xs details"');
             echo '</div>';
         ?>
         </div>
index c42476bff905467e1134e1565af83967e0aa4f4b..2b8c14951551b0f359d72518cd51e78484fb514e 100644 (file)
@@ -53,7 +53,7 @@
                     echo ' <span class="type">('.ucwords(str_replace('_',' ',$aResult['class'])).')</span>';
                 else
                     echo ' <span class="type">('.ucwords(str_replace('_',' ',$aResult['type'])).')</span>';
-                echo ' <a class="btn btn-default btn-xs details" href="details.php?osmtype='.$aResult['osm_type'].'&osmid='.$aResult['osm_id'].'&class='.$aResult['class'].'">details</a>';
+                echo detailsPermaLink($aResult, 'details', 'class="btn btn-default btn-xs details"');
                 echo '</div>';
                 $i = $i+1;
             }
diff --git a/test/php/Nominatim/OutputTest.php b/test/php/Nominatim/OutputTest.php
new file mode 100644 (file)
index 0000000..b243ba4
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+
+namespace Nominatim;
+
+require_once(CONST_BasePath.'/lib/output.php');
+
+class OutputTest extends \PHPUnit\Framework\TestCase
+{
+    public function testDetailsPermaLinkNode()
+    {
+        $aFeature = array('osm_type' => 'N', 'osm_id'=> 38274, 'class' => 'place');
+        $this->assertSame(
+            detailsPermaLink($aFeature),
+            '<a href="details.php?osmtype=N&osmid=38274&class=place">node 38274</a>'
+        );
+    }
+
+    public function testDetailsPermaLinkWay()
+    {
+        $aFeature = array('osm_type' => 'W', 'osm_id'=> 65, 'class' => 'highway');
+        $this->assertSame(
+            detailsPermaLink($aFeature),
+            '<a href="details.php?osmtype=W&osmid=65&class=highway">way 65</a>'
+        );
+    }
+
+    public function testDetailsPermaLinkRelation()
+    {
+        $aFeature = array('osm_type' => 'R', 'osm_id'=> 9908, 'class' => 'waterway');
+        $this->assertSame(
+            detailsPermaLink($aFeature),
+            '<a href="details.php?osmtype=R&osmid=9908&class=waterway">relation 9908</a>'
+        );
+    }
+
+    public function testDetailsPermaLinkTiger()
+    {
+        $aFeature = array('osm_type' => 'T', 'osm_id'=> 2, 'place_id' => 334);
+        $this->assertSame(
+            detailsPermaLink($aFeature, 'foo'),
+            '<a href="details.php?place_id=334">foo</a>'
+        );
+    }
+
+    public function testDetailsPermaLinkInterpolation()
+    {
+        $aFeature = array('osm_type' => 'I', 'osm_id'=> 400, 'place_id' => 3);
+        $this->assertSame(
+            detailsPermaLink($aFeature, 'foo'),
+            '<a href="details.php?place_id=3">foo</a>'
+        );
+    }
+
+    public function testDetailsPermaLinkWithExtraPropertiesNode()
+    {
+        $aFeature = array('osm_type' => 'N', 'osm_id'=> 2, 'class' => 'amenity');
+        $this->assertSame(
+            detailsPermaLink($aFeature, 'something', 'class="xtype"'),
+            '<a class="xtype" href="details.php?osmtype=N&osmid=2&class=amenity">something</a>'
+        );
+    }
+
+    public function testDetailsPermaLinkWithExtraPropertiesTiger()
+    {
+        $aFeature = array('osm_type' => 'T', 'osm_id'=> 5, 'place_id' => 46);
+        $this->assertSame(
+            detailsPermaLink($aFeature, 'something', 'class="xtype"'),
+            '<a class="xtype" href="details.php?place_id=46">something</a>'
+        );
+    }
+}
index 44d4956b4d2845e166dcd8dfac32d8d815a5c9f0..39fa0afa901ff01ab8531b5df31896fac8be3ed9 100644 (file)
@@ -44,6 +44,16 @@ if ($sOsmType && $iOsmId > 0) {
     $sSQL .= ' ORDER BY class ASC';
     $sPlaceId = $oDB->getOne($sSQL, array(':type' => $sOsmType, ':id' => $iOsmId));
 
+
+    // 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
 
     if (!$sPlaceId) {