+ END IF;
+
+ END LOOP;
+
+ END IF;
+
+--RAISE WARNING 'x4 %',NEW.parent_place_id;
+ -- Still nothing, just use the nearest road
+ IF NEW.parent_place_id IS NULL THEN
+ FOR location IN SELECT place_id FROM getNearestRoadFeature(NEW.partition, place_centroid) LOOP
+ NEW.parent_place_id := location.place_id;
+ END LOOP;
+ END IF;
+
+--return NEW;
+--RAISE WARNING 'x6 %',NEW.parent_place_id;
+
+ -- If we didn't find any road fallback to standard method
+ IF NEW.parent_place_id IS NOT NULL THEN
+
+ -- Get the details of the parent road
+ 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
+ return NEW;
+ END IF;
+
+ -- Merge address from parent
+ nameaddress_vector := array_merge(nameaddress_vector, location.nameaddress_vector);
+ nameaddress_vector := array_merge(nameaddress_vector, location.name_vector);
+
+ -- 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.calculated_country_code, NEW.partition, name_vector, NEW.rank_search, NEW.rank_address, NEW.geometry);
+ END IF;
+
+ result := insertSearchName(NEW.partition, NEW.place_id, NEW.calculated_country_code, name_vector, nameaddress_vector, NEW.rank_search, NEW.rank_address, NEW.importance, place_centroid, NEW.geometry);
+
+ return NEW;
+ END IF;
+
+ END IF;
+
+-- RAISE WARNING ' INDEXING Started:';
+-- RAISE WARNING ' INDEXING: %',NEW;
+
+ -- ---------------------------------------------------------------------------
+ -- Full indexing
+
+ 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;
+
+-- RAISE WARNING 'get_osm_rel_members, label';
+ IF relation_members IS NOT NULL THEN
+ FOR relMember IN select get_osm_rel_members(relation_members,ARRAY['label']) as member LOOP
+
+ 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 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));
+ END IF;
+
+ -- merge in the label name, re-init word vector
+ IF NOT linkedPlacex.name IS NULL THEN
+ NEW.name := linkedPlacex.name || NEW.name;
+ name_vector := array_merge(name_vector, make_keywords(linkedPlacex.name));