- ---- convert address store to array of tokenids
- IF address IS NOT NULL THEN
- FOR addr_item IN SELECT * FROM each(address)
- LOOP
- IF addr_item.key IN ('city', 'tiger:county', 'state', 'suburb', 'province',
- 'district', 'region', 'county', 'municipality',
- 'hamlet', 'village', 'subdistrict', 'town',
- 'neighbourhood', 'quarter', 'parish')
- THEN
- isin_tokens := array_merge(isin_tokens,
- word_ids_from_name(addr_item.value));
- IF NOT %REVERSE-ONLY% THEN
- nameaddress_vector := array_merge(nameaddress_vector,
- addr_ids_from_name(addr_item.value));
+ address_havelevel := array_fill(false, ARRAY[maxrank]);
+
+ FOR location IN
+ SELECT * FROM get_places_for_addr_tags(partition, geometry,
+ address, country)
+ ORDER BY rank_address, distance, isguess desc
+ LOOP
+ IF NOT %REVERSE-ONLY% THEN
+ nameaddress_vector := array_merge(nameaddress_vector,
+ location.keywords::int[]);
+ END IF;
+
+ IF location.place_id is not null THEN
+ location_isaddress := not address_havelevel[location.rank_address];
+ IF not address_havelevel[location.rank_address] THEN
+ address_havelevel[location.rank_address] := true;
+ IF parent_place_rank < location.rank_address THEN
+ parent_place_id := location.place_id;
+ parent_place_rank := location.rank_address;