]> git.openstreetmap.org Git - nominatim.git/commitdiff
make sure outputs take into account linked place names
authorSarah Hoffmann <lonvia@denofr.de>
Wed, 16 Mar 2022 20:44:52 +0000 (21:44 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Wed, 16 Mar 2022 20:44:52 +0000 (21:44 +0100)
lib-php/ParameterParser.php
lib-sql/functions/placex_triggers.sql
test/bdd/db/query/linking.feature
test/bdd/db/update/linked_places.feature
test/bdd/steps/http_responses.py

index dd637722aacd737804e521906b2827c2060c71ed..e70b47be044354271bf8e832554d60f8c7289a1c 100644 (file)
@@ -114,21 +114,26 @@ class ParameterParser
         }
 
         foreach ($aLanguages as $sLanguage => $fLanguagePref) {
-            $aLangPrefOrder['name:'.$sLanguage] = 'name:'.$sLanguage;
+            $this->addNameTag($aLangPrefOrder, 'name:'.$sLanguage);
         }
-        $aLangPrefOrder['name'] = 'name';
-        $aLangPrefOrder['brand'] = 'brand';
+        $this->addNameTag($aLangPrefOrder, 'name');
+        $this->addNameTag($aLangPrefOrder, 'brand');
         foreach ($aLanguages as $sLanguage => $fLanguagePref) {
-            $aLangPrefOrder['official_name:'.$sLanguage] = 'official_name:'.$sLanguage;
-            $aLangPrefOrder['short_name:'.$sLanguage] = 'short_name:'.$sLanguage;
+            $this->addNameTag($aLangPrefOrder, 'official_name:'.$sLanguage);
+            $this->addNameTag($aLangPrefOrder, 'short_name:'.$sLanguage);
         }
-        $aLangPrefOrder['official_name'] = 'official_name';
-        $aLangPrefOrder['short_name'] = 'short_name';
-        $aLangPrefOrder['ref'] = 'ref';
-        $aLangPrefOrder['type'] = 'type';
+        $this->addNameTag($aLangPrefOrder, 'official_name');
+        $this->addNameTag($aLangPrefOrder, 'short_name');
+        $this->addNameTag($aLangPrefOrder, 'ref');
+        $this->addNameTag($aLangPrefOrder, 'type');
         return $aLangPrefOrder;
     }
 
+    private function addNameTag(&$aLangPrefOrder, $sTag) {
+        $aLangPrefOrder[$sTag] = $sTag;
+        $aLangPrefOrder['_place_'.$sTag] = '_place_'.$sTag;
+    }
+
     public function hasSetAny($aParamNames)
     {
         foreach ($aParamNames as $sName) {
index e6f083c894aa1d3d517f4eddd96551eaec4de9dc..9463bb27a8ed4e50f04cfcc4850ba7b830936fe4 100644 (file)
@@ -85,7 +85,10 @@ BEGIN
         FROM each(location.name - result.name);
       {% if debug %}RAISE WARNING 'Extra names: %', extra_names;{% endif %}
 
-      result.name := location.name || result.name || extra_names;
+      IF extra_names is not null THEN
+          result.name := result.name || extra_names;
+      END IF;
+
       {% if debug %}RAISE WARNING 'Final names: %', result.name;{% endif %}
     END IF;
   END IF;
index d11ba31f8aa168e0eb1eb565c74bb2ff76da99b3..cf1fa20c243691e48a4e3d98f707ee03a1845785 100644 (file)
@@ -18,8 +18,14 @@ Feature: Searching linked places
          | N2      | R13 |
         When sending search query "Vario"
         Then results contain
-         | osm |
-         | R13 |
+         | osm | display_name |
+         | R13 | Garbo |
+        When sending search query "Vario"
+         | accept-language |
+         | it |
+        Then results contain
+         | osm | display_name |
+         | R13 | Vario |
 
 
     Scenario: Differing names from linked places are searchable
@@ -38,5 +44,9 @@ Feature: Searching linked places
          | N2      | R13 |
         When sending search query "Vario"
         Then results contain
-         | osm |
-         | R13 |
+         | osm | display_name |
+         | R13 | Garbo |
+        When sending search query "Garbo"
+        Then results contain
+         | osm | display_name |
+         | R13 | Garbo |
index 7a0fa21a829667102a177e9abf3ad3671cd7c1a2..99614b7f749aa4f7bf1b082ff7974aca259e1d41 100644 (file)
@@ -117,8 +117,10 @@ Feature: Updates of linked places
          | 1  | N3:label |
         When importing
         Then placex contains
-         | object | linked_place_id | name+name:de |
+         | object | linked_place_id | name+_place_name:de |
          | R1     | -               | pnt  |
+        And placex contains
+         | object | linked_place_id | name+name:de |
          | N3     | R1              | pnt  |
         When updating places
          | osm | class    | type        | name+name:de | admin | geometry |
@@ -126,8 +128,43 @@ Feature: Updates of linked places
         Then placex contains
          | object | linked_place_id | name+name:de |
          | N3     | R1              | newname  |
+        And placex contains
+         | object | linked_place_id | name+_place_name:de |
          | R1     | -               | newname  |
 
+    Scenario: Update linking relation when linkee name is deleted
+        Given the places
+         | osm | class    | type           | name | admin | geometry |
+         | R1  | boundary | administrative | rel  | 8     | poly-area:0.1 |
+        And the places
+         | osm | class    | type           | name | admin | geometry |
+         | N3  | place    | city           | pnt  | 30    | 0.00001 0 |
+        And the relations
+         | id | members  |
+         | 1  | N3:label |
+        When importing
+        Then placex contains
+         | object | linked_place_id | name+_place_name | name+name |
+         | R1     | -               | pnt              | rel       |
+        And placex contains
+         | object | linked_place_id | name+name |
+         | N3     | R1              | pnt  |
+        When sending search query "pnt"
+        Then results contain
+          | osm |
+          | R1  |
+        When updating places
+         | osm | class    | type        | name+name:de | admin | geometry |
+         | N3  | place    | city        | depnt        | 30    | 0.00001 0 |
+        Then placex contains
+         | object | linked_place_id | name+name:de |
+         | N3     | R1              | depnt  |
+        And placex contains
+         | object | linked_place_id | name+_place_name:de | name+name |
+         | R1     | -               | depnt               | rel       |
+        When sending search query "pnt"
+        Then exactly 0 results are returned
+
     Scenario: Updating linkee extratags keeps linker's extratags
         Given the named places
          | osm | class    | type           | extra+wikidata | admin | geometry |
index fa841d25be068147b298fa20124d06366d35c997..035838a5a9c0bf7952cfe62154942f54219b1039 100644 (file)
@@ -62,8 +62,6 @@ class GenericResponse:
 
         if errorcode == 200 and fmt != 'debug':
             getattr(self, '_parse_' + fmt)()
-        else:
-            print("Bad response: ", page)
 
     def _parse_json(self):
         m = re.fullmatch(r'([\w$][^(]*)\((.*)\)', self.page)
@@ -74,13 +72,14 @@ class GenericResponse:
             self.header['json_func'] = m.group(1)
         self.result = json.JSONDecoder(object_pairs_hook=OrderedDict).decode(code)
         if isinstance(self.result, OrderedDict):
-            self.result = [self.result]
+            if 'error' in self.result:
+                self.result = []
+            else:
+                self.result = [self.result]
 
     def _parse_geojson(self):
         self._parse_json()
-        if 'error' in self.result[0]:
-            self.result = []
-        else:
+        if self.result:
             self.result = list(map(_geojson_result_to_json_result, self.result[0]['features']))
 
     def _parse_geocodejson(self):