-- start
IF in_partition = -partition- THEN
FOR r IN
- SELECT place_id, keywords, rank_address, rank_search, ST_Distance(point, centroid) as distance FROM (
+ SELECT place_id, keywords, rank_address, rank_search, min(ST_Distance(point, centroid)) as distance FROM (
SELECT * FROM location_area_large_-partition- WHERE ST_Contains(geometry, point) and rank_search < maxrank
UNION ALL
SELECT * FROM location_area_country WHERE ST_Contains(geometry, point) and rank_search < maxrank
) as location_area
- ORDER BY rank_address desc, isin_tokens && keywords desc, isguess asc, ST_Distance(point, centroid) * CASE WHEN rank_address = 16 AND rank_search = 16 THEN 0.25 WHEN rank_address = 16 AND rank_search = 17 THEN 0.5 ELSE 1 END ASC
+ GROUP BY place_id, keywords, rank_address, rank_search, isguess, centroid
+ ORDER BY rank_address desc, isin_tokens && keywords desc, isguess asc,
+ ST_Distance(point, centroid) *
+ CASE
+ WHEN rank_address = 16 AND rank_search = 15 THEN 0.2 -- capital city
+ WHEN rank_address = 16 AND rank_search = 16 THEN 0.25 -- city
+ WHEN rank_address = 16 AND rank_search = 17 THEN 0.5 -- town
+ ELSE 1 END ASC -- everything else
LOOP
RETURN NEXT r;
END LOOP;
create or replace function insertSearchName(
in_partition INTEGER, in_place_id integer, in_country_code VARCHAR(2),
in_name_vector INTEGER[], in_nameaddress_vector INTEGER[],
- in_rank_search INTEGER, in_rank_address INTEGER,
+ in_rank_search INTEGER, in_rank_address INTEGER, in_importance FLOAT,
in_centroid GEOMETRY) RETURNS BOOLEAN AS $$
DECLARE
BEGIN
DELETE FROM search_name WHERE place_id = in_place_id;
- INSERT INTO search_name values (in_place_id, in_rank_search, in_rank_address, 0, in_country_code,
+ INSERT INTO search_name values (in_place_id, in_rank_search, in_rank_address, in_importance, in_country_code,
in_name_vector, in_nameaddress_vector, in_centroid);
IF in_rank_search <= 4 THEN
DELETE FROM search_name_country WHERE place_id = in_place_id;
- INSERT INTO search_name_country values (in_place_id, in_rank_search, in_rank_address, 0, in_country_code,
+ INSERT INTO search_name_country values (in_place_id, in_rank_search, in_rank_address, in_importance, in_country_code,
in_name_vector, in_nameaddress_vector, in_centroid);
RETURN TRUE;
END IF;