- -- Is the WAY part of a relation
- FOR relation IN select * from planet_osm_rels where parts @> ARRAY[location.osm_id::integer] and members @> ARRAY['w'||location.osm_id]
- LOOP
- -- At the moment we only process one type of relation - associatedStreet
- IF relation.tags @> ARRAY['associatedStreet'] AND array_upper(relation.members, 1) IS NOT NULL THEN
- FOR i IN 1..array_upper(relation.members, 1) BY 2 LOOP
- IF NEW.street_place_id IS NULL AND relation.members[i+1] = 'street' THEN
---RAISE WARNING 'node in way that is in a relation %',relation;
- SELECT place_id from placex where osm_type='W' and osm_id = substring(relation.members[i],2,200)::integer
- and rank_search = 26 INTO NEW.street_place_id;
- END IF;
- END LOOP;
- END IF;
- END LOOP;
-
- -- If the way contains an explicit name of a street copy it
- IF NEW.street IS NULL AND location.street IS NOT NULL THEN
---RAISE WARNING 'node in way that has a streetname %',location;
- NEW.street := location.street;
+ -- If there is no name it isn't searchable, don't bother to create a search record
+ IF NEW.name is NULL THEN
+ --DEBUG: RAISE WARNING 'Not a searchable place % %', NEW.osm_type, NEW.osm_id;
+ return NEW;
+ END IF;
+
+ -- Performance, it would be more acurate to do all the rest of the import
+ -- process but it takes too long
+ -- Just be happy with inheriting from parent road only
+ IF NEW.rank_search <= 25 and NEW.rank_address > 0 THEN
+ result := add_location(NEW.place_id, NEW.country_code, NEW.partition, name_vector, NEW.rank_search, NEW.rank_address, upper(trim(NEW.address->'postcode')), NEW.geometry);
+ --DEBUG: RAISE WARNING 'Place added to location table';
+ END IF;
+
+ result := insertSearchName(NEW.partition, NEW.place_id, name_vector,
+ NEW.rank_search, NEW.rank_address, NEW.geometry);
+
+ IF NOT %REVERSE-ONLY% THEN
+ -- Merge address from parent
+ SELECT s.name_vector, s.nameaddress_vector FROM search_name s
+ WHERE s.place_id = NEW.parent_place_id INTO location;
+
+ nameaddress_vector := array_merge(nameaddress_vector,
+ location.nameaddress_vector);
+ nameaddress_vector := array_merge(nameaddress_vector, location.name_vector);
+
+ INSERT INTO search_name (place_id, search_rank, address_rank,
+ importance, country_code, name_vector,
+ nameaddress_vector, centroid)
+ VALUES (NEW.place_id, NEW.rank_search, NEW.rank_address,
+ NEW.importance, NEW.country_code, name_vector,
+ nameaddress_vector, place_centroid);
+ --DEBUG: RAISE WARNING 'Place added to search table';
+ END IF;
+
+ return NEW;
+ END IF;
+
+ END IF;
+
+ -- ---------------------------------------------------------------------------
+ -- Full indexing
+ --DEBUG: RAISE WARNING 'Using full index mode for % %', NEW.osm_type, NEW.osm_id;
+
+ IF NEW.osm_type = 'R' AND NEW.rank_search < 26 THEN
+
+ -- see if we have any special relation members
+ select members from planet_osm_rels where id = NEW.osm_id INTO relation_members;
+ --DEBUG: RAISE WARNING 'Got relation members';
+
+ IF relation_members IS NOT NULL THEN
+ FOR relMember IN select get_osm_rel_members(relation_members,ARRAY['label']) as member LOOP
+ --DEBUG: RAISE WARNING 'Found label member %', relMember.member;
+
+ FOR linkedPlacex IN select * from placex where osm_type = upper(substring(relMember.member,1,1))::char(1)
+ and osm_id = substring(relMember.member,2,10000)::bigint
+ and class = 'place' order by rank_search desc limit 1 LOOP
+
+ -- If we don't already have one use this as the centre point of the geometry
+ IF NEW.centroid IS NULL THEN
+ NEW.centroid := coalesce(linkedPlacex.centroid,st_centroid(linkedPlacex.geometry));