]> git.openstreetmap.org Git - nominatim.git/commitdiff
merge linked names correctly into namedetails
authorSarah Hoffmann <lonvia@denofr.de>
Thu, 17 Mar 2022 10:02:02 +0000 (11:02 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Thu, 17 Mar 2022 10:02:02 +0000 (11:02 +0100)
Convert the '_place_*' entries back to normal entries before
returning them in the 'namedetails' section. If the name field is
duplicated, kept the '_place_*' notation. This preserves the previous
behaviour before _place_ names were introduces but adds the additional
names from the linked place for reference.

lib-php/PlaceLookup.php
test/bdd/db/query/linking.feature
test/bdd/steps/http_responses.py

index 120f55436acb482de8d374019b2a30b05ffd2c0b..715f1ced3daab48dbd95b374465f44ff6e93d050 100644 (file)
@@ -452,11 +452,7 @@ class PlaceLookup
             }
 
             if ($this->bNameDetails) {
             }
 
             if ($this->bNameDetails) {
-                if ($aPlace['names']) {
-                    $aPlace['sNameDetails'] = json_decode($aPlace['names']);
-                } else {
-                    $aPlace['sNameDetails'] = (object) array();
-                }
+                $aPlace['sNameDetails'] = $this->extractNames($aPlace['names']);
             }
 
             $aPlace['addresstype'] = ClassTypes\getLabelTag(
             }
 
             $aPlace['addresstype'] = ClassTypes\getLabelTag(
@@ -479,6 +475,33 @@ class PlaceLookup
         return $aResults;
     }
 
         return $aResults;
     }
 
+
+    private function extractNames($sNames)
+    {
+        if (!$sNames) {
+            return (object) array();
+        }
+
+        $aFullNames = json_decode($sNames);
+        $aNames = array();
+
+        foreach ($aFullNames as $sKey => $sValue) {
+            if (strpos($sKey, '_place_') === 0) {
+                $sSubKey = substr($sKey, 7);
+                if (array_key_exists($sSubKey, $aFullNames)) {
+                    $aNames[$sKey] = $sValue;
+                } else {
+                    $aNames[$sSubKey] = $sValue;
+                }
+            } else {
+                $aNames[$sKey] = $sValue;
+            }
+        }
+
+        return $aNames;
+    }
+
+
     /* returns an array which will contain the keys
      *   aBoundingBox
      * and may also contain one or more of the keys
     /* returns an array which will contain the keys
      *   aBoundingBox
      * and may also contain one or more of the keys
@@ -489,8 +512,6 @@ class PlaceLookup
      *   lat
      *   lon
      */
      *   lat
      *   lon
      */
-
-
     public function getOutlines($iPlaceID, $fLon = null, $fLat = null, $fRadius = null, $fLonReverse = null, $fLatReverse = null)
     {
 
     public function getOutlines($iPlaceID, $fLon = null, $fLat = null, $fRadius = null, $fLonReverse = null, $fLatReverse = null)
     {
 
index cf1fa20c243691e48a4e3d98f707ee03a1845785..bd8e1da0329c58dfc19a03c8b7bfd69e5314f60b 100644 (file)
@@ -17,9 +17,11 @@ Feature: Searching linked places
          | object  | linked_place_id |
          | N2      | R13 |
         When sending search query "Vario"
          | object  | linked_place_id |
          | N2      | R13 |
         When sending search query "Vario"
+         | namedetails |
+         | 1 |
         Then results contain
         Then results contain
-         | osm | display_name |
-         | R13 | Garbo |
+         | osm | display_name | namedetails |
+         | R13 | Garbo | "name": "Garbo", "name:it": "Vario" |
         When sending search query "Vario"
          | accept-language |
          | it |
         When sending search query "Vario"
          | accept-language |
          | it |
@@ -43,9 +45,11 @@ Feature: Searching linked places
          | object  | linked_place_id |
          | N2      | R13 |
         When sending search query "Vario"
          | object  | linked_place_id |
          | N2      | R13 |
         When sending search query "Vario"
+         | namedetails |
+         | 1 |
         Then results contain
         Then results contain
-         | osm | display_name |
-         | R13 | Garbo |
+         | osm | display_name | namedetails |
+         | R13 | Garbo        | "name": "Garbo", "_place_name": "Vario" |
         When sending search query "Garbo"
         Then results contain
          | osm | display_name |
         When sending search query "Garbo"
         Then results contain
          | osm | display_name |
index 035838a5a9c0bf7952cfe62154942f54219b1039..3b9f59ebc1626aae952c44116fbf0745b12d0eef 100644 (file)
@@ -102,6 +102,9 @@ class GenericResponse:
         elif value.startswith("^"):
             assert re.fullmatch(value, self.result[idx][field]), \
                    BadRowValueAssert(self, idx, field, value)
         elif value.startswith("^"):
             assert re.fullmatch(value, self.result[idx][field]), \
                    BadRowValueAssert(self, idx, field, value)
+        elif isinstance(self.result[idx][field], OrderedDict):
+            assert self.result[idx][field] == eval('{' + value + '}'), \
+                   BadRowValueAssert(self, idx, field, value)
         else:
             assert str(self.result[idx][field]) == str(value), \
                    BadRowValueAssert(self, idx, field, value)
         else:
             assert str(self.result[idx][field]) == str(value), \
                    BadRowValueAssert(self, idx, field, value)