diff --git a/geocoder/admin1/sql/geocoder.sql b/geocoder/admin1/sql/geocoder.sql index efc3b9d..8d0d012 100644 --- a/geocoder/admin1/sql/geocoder.sql +++ b/geocoder/admin1/sql/geocoder.sql @@ -1,64 +1,5 @@ --- Usage ---SELECT (geocode_admin1_polygons(Array['TX','Cuidad Real', 'sevilla'])).* - ---- Function - -CREATE OR REPLACE FUNCTION test_geocode_admin1_polygons(name text[]) - RETURNS SETOF geocode_admin_v1 AS $$ - DECLARE - ret geocode_admin_v1%rowtype; - BEGIN - FOR ret IN - SELECT - q, geom, CASE WHEN geom IS NULL THEN FALSE ELSE TRUE END AS success - FROM ( - SELECT - q, ( - SELECT the_geom - FROM global_province_polygons - WHERE d.c = ANY (synonyms) - -- To calculate frequency, I simply counted the number of users - -- we had signed up in each country. Countries with more users, - -- we favor higher in the geocoder :) - ORDER BY frequency DESC LIMIT 1 - ) geom - FROM (SELECT trim(replace(lower(unnest(name)),'.',' ')) c, unnest(name) q) d - ) v - LOOP - RETURN NEXT ret; - END LOOP; - RETURN; -END -$$ LANGUAGE 'plpgsql' SECURITY DEFINER; -Text array, country name - - --- CREATE OR REPLACE FUNCTION test_geocode_admin1_polygons(name text[]) --- RETURNS SETOF geocode_admin_v1 AS $$ --- DECLARE --- ret geocode_admin_v1%rowtype; --- BEGIN --- -- FOR ret IN --- RETURN QUERY --- SELECT --- d.q, n.the_geom as geom, --- CASE WHEN s.adm1_code IS NULL then FALSE ELSE TRUE END AS success --- FROM ( --- SELECT --- q, lower(regexp_replace(q, '[^a-zA-Z\u00C0-\u00ff]+', '', 'g'))::text x --- FROM (SELECT unnest(name) q) g --- ) d --- LEFT OUTER JOIN --- admin1_synonyms s ON name_ = d.x --- LEFT OUTER JOIN --- ne_admin1_v3 n ON s.adm1_code = n.adm1_code; --- END --- $$ LANGUAGE 'plpgsql' SECURITY DEFINER; - - ---- Usage - --- SELECT (geocode_admin1_polygons(Array['az', 'Texas'], 'Ecuador')).* --- Function diff --git a/geocoder/setup/indexes.sql b/geocoder/setup/indexes.sql index bfd1da4..4def421 100644 --- a/geocoder/setup/indexes.sql +++ b/geocoder/setup/indexes.sql @@ -7,3 +7,5 @@ CREATE INDEX idx_admin0_synonyms_rank ON admin0_synonyms (rank); -- create indexes on polygon table CREATE UNIQUE INDEX idx_ne_admin0_v3_adm0_a3 ON ne_admin0_v3 (adm0_a3); +-- create indexes on postal code polygon table +CREATE UNIQUE INDEX idx_postal_code_polygons_a3_code ON postal_code_polygons (adm0_a3, postal_code) \ No newline at end of file