added synonym readme

This commit is contained in:
andrewxhill 2014-09-20 00:15:20 +02:00
parent aee9556afa
commit 322b30c724
2 changed files with 11 additions and 2 deletions

View File

@ -71,4 +71,13 @@ __notes:__
- The column `adm0_a3` will be used as a unique identifier.
- The ranks are somewhat arbitrarily organized and should be modified later based on our users use of the geocoder (will users more commonly geocode an adm0_a3 or abbreviation?)
- I also forgot to assign a `rank` of `2` to a synonym.
- I also forgot to assign a `rank` of `2` to a synonym.
# Admin0 Synonym Service
If you need to look up the iso code for any list of countries without returning any geometries, you can use the endpoint defined in sql/synonym_service.sql. An example works like this,
```sql
SELECT (admin0_synonym_lookup(Array['United States', 'ESP'])).*
```

View File

@ -10,6 +10,6 @@ CREATE OR REPLACE FUNCTION admin0_synonym_lookup(name text[])
BEGIN
-- FOR ret IN
RETURN QUERY
SELECT d.q, n.adm0_a3 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 admin0_synonyms s ON name_ = d.x GROUP BY d.q, n.adm0_a3;
SELECT d.q, s.adm0_a3 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 admin0_synonyms s ON name_ = d.x GROUP BY d.q, s.adm0_a3;
END
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;