]> git.openstreetmap.org Git - nominatim.git/commitdiff
merge addr:postcode from houses into search index of attached road
authorSarah Hoffmann <lonvia@denofr.de>
Fri, 8 May 2015 17:34:33 +0000 (19:34 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Fri, 8 May 2015 17:34:33 +0000 (19:34 +0200)
Makes house number searchable by postcode when the postcode is
only available in addr:postcode.

sql/functions.sql
tests/features/db/import/search_terms.feature

index c54bcad92ca54d99bd01d1f710ed581439ee3f12..3c8f16e0831a5696d7974f48889183bc79b9fc10 100644 (file)
@@ -1403,6 +1403,26 @@ BEGIN
         select * from search_name where place_id = NEW.parent_place_id INTO location;
         NEW.calculated_country_code := location.country_code;
 
+        -- Merge the postcode into the parent's address if necessary XXXX
+        IF NEW.postcode IS NOT NULL THEN
+          isin_tokens := '{}'::int[];
+          address_street_word_id := getorcreate_word_id(make_standard_name(NEW.postcode));
+          IF address_street_word_id is not null
+             and not ARRAY[address_street_word_id] <@ location.nameaddress_vector THEN
+             isin_tokens := isin_tokens || address_street_word_id;
+          END IF;
+          address_street_word_id := getorcreate_name_id(make_standard_name(NEW.postcode));
+          IF address_street_word_id is not null
+             and not ARRAY[address_street_word_id] <@ location.nameaddress_vector THEN
+             isin_tokens := isin_tokens || address_street_word_id;
+          END IF;
+          IF isin_tokens != '{}'::int[] THEN
+             UPDATE search_name
+                SET nameaddress_vector = search_name.nameaddress_vector || isin_tokens
+              WHERE place_id = NEW.parent_place_id;
+          END IF;
+        END IF;
+
 --RAISE WARNING '%', NEW.name;
         -- If there is no name it isn't searchable, don't bother to create a search record
         IF NEW.name is NULL THEN
index 642b3ea8974f8d71aa42706d09faada5e79d2751..f68fe61ca70fc02b61f06eb3893418354e57d3e3 100644 (file)
@@ -26,3 +26,17 @@ Feature: Creation of search terms
         Then search_name table contains
          | place_id | name_vector | nameaddress_vector
          | N1       | foo         | the road
+
+    Scenario: Roads take over the postcode from attached houses
+        Given the scene roads-with-pois
+        And the place nodes
+         | osm_id | class | type  | housenumber | postcode | street   | geometry
+         | 1      | place | house | 1           | 12345    | North St |:p-S1
+        And the place ways
+         | osm_id | class   | type        | name     | geometry
+         | 1      | highway | residential | North St | :w-north
+        When importing
+        Then search_name table contains
+         | place_id | nameaddress_vector
+         | W1       | 12345
+