pelias / wof-admin-lookup

Who's on First Admin Lookup for the Pelias Geocoder
https://pelias.io
MIT License
9 stars 24 forks source link

Use 3-character country code for dependencies where possible #311

Closed orangejulius closed 2 years ago

orangejulius commented 2 years ago

After https://github.com/pelias/api/pull/1622, which extends the boundary.country API parameter to include the dependency placetype, we noticed that venue and address records often have a 2-character country code when they are part of a dependency.

The boundary.country parameter currently checks only for 3-character codes, and so the best solution is to ensure the relevant property on all records in Elasticsearch is a 3-character country code whenever possible.

This change expands on the logic for selecting an abbreviation for an admin record to be used for point in polygon lookup. Logic specific to countries is expanded to include dependencies, and some additional possible fields that might contain 3-character codes are checked.

Because the abbreviation logic is now a bit more substantial, it's extracted into its own function. It's also been made a bit less redundant and hopefully more clear.