-CREATE OR REPLACE FUNCTION search_name_add_words(parent_place_id BIGINT, to_add INTEGER[])
- RETURNS BOOLEAN
- AS $$
-DECLARE
- childplace RECORD;
-BEGIN
-
- IF #to_add = 0 THEN
- RETURN true;
- END IF;
-
- -- this should just be an update, but it seems to do insane things to the index size (delete and insert doesn't)
- FOR childplace IN select * from search_name,place_addressline
- where address_place_id = parent_place_id
- and search_name.place_id = place_addressline.place_id
- LOOP
- delete from search_name where place_id = childplace.place_id;
- IF not (ARRAY[to_add] <@ childplace.nameaddress_vector) THEN
- childplace.nameaddress_vector := childplace.nameaddress_vector || to_add;
- END IF;
- IF childplace.place_id = parent_place_id and not (ARRAY[to_add] <@ childplace.name_vector) THEN
- childplace.name_vector := childplace.name_vector || to_add;
- END IF;
- insert into search_name (place_id, search_rank, address_rank, country_code, name_vector, nameaddress_vector, centroid)
- values (childplace.place_id, childplace.search_rank, childplace.address_rank, childplace.country_code,
- childplace.name_vector, childplace.nameaddress_vector, childplace.centroid);
- END LOOP;
-
- RETURN true;
-END;
-$$
-LANGUAGE plpgsql;
-
-CREATE OR REPLACE FUNCTION update_location_nameonly(partition INTEGER, OLD_place_id BIGINT, name hstore) RETURNS BOOLEAN
- AS $$
-DECLARE
- newkeywords INTEGER[];
- addedkeywords INTEGER[];
- removedkeywords INTEGER[];
-BEGIN
-
- -- what has changed?
- newkeywords := make_keywords(name);
- select coalesce(newkeywords,'{}'::INTEGER[]) - coalesce(location_point.keywords,'{}'::INTEGER[]),
- coalesce(location_point.keywords,'{}'::INTEGER[]) - coalesce(newkeywords,'{}'::INTEGER[]) from location_point
- where place_id = OLD_place_id into addedkeywords, removedkeywords;
-
--- RAISE WARNING 'update_location_nameonly for %: new:% added:% removed:%', OLD_place_id, newkeywords, addedkeywords, removedkeywords;
-
- IF #removedkeywords > 0 THEN
- -- abort due to tokens removed
- RETURN false;
- END IF;
-
- IF #addedkeywords > 0 THEN
- -- short circuit - no changes
- RETURN true;
- END IF;
-
- UPDATE location_area set keywords = newkeywords where place_id = OLD_place_id;
- RETURN search_name_add_words(OLD_place_id, addedkeywords);
-END;
-$$
-LANGUAGE plpgsql;