From 080de34163c3fd9b3793c357131bec8f19dedb7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Ignacio=20S=C3=A1nchez=20Lara?= Date: Mon, 16 Jul 2018 12:11:40 +0200 Subject: [PATCH] match_types for Mapbox metadata --- .../cartodb_services/mapbox/geocoder.py | 16 +++++++++++++++- test/integration/test_street_functions.py | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py b/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py index 9eb5e4e..1fc8b4e 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py @@ -25,6 +25,17 @@ TYPE_POINT = 'Point' EMPTY_RESPONSE = [[], {}] +MATCH_TYPE_BY_MATCH_LEVEL = { + 'poi': 'point_of_interest', + 'poi.landmark': 'point_of_interest', + 'place': 'point_of_interest', + 'country': 'country', + 'region': 'state', + 'locality': 'locality', + 'district': 'district', + 'address': 'street' +} + class MapboxGeocoder(Traceable): ''' @@ -80,9 +91,12 @@ class MapboxGeocoder(Traceable): else: precision = PRECISION_PRECISE + match_types = [MATCH_TYPE_BY_MATCH_LEVEL.get(match_level, None) + for match_level in result['place_type']] return { 'relevance': self._normalize_relevance(float(result['relevance'])), - 'precision': precision + 'precision': precision, + 'match_types': filter(None, match_types) } def _normalize_relevance(self, relevance): diff --git a/test/integration/test_street_functions.py b/test/integration/test_street_functions.py index 1c05058..86d03c6 100644 --- a/test/integration/test_street_functions.py +++ b/test/integration/test_street_functions.py @@ -92,9 +92,9 @@ class TestStreetFunctionsSetUp(TestCase): MAPBOX_METADATAS = { 'Plaza España, Barcelona': - {'relevance': 0.666, 'precision': 'precise'}, + {'relevance': 0.666, 'precision': 'precise', 'match_types': ['point_of_interest']}, 'Santiago Rusiñol 123, Valladolid': - {'relevance': 0.666, 'precision': 'precise'} # TODO: wrong + {'relevance': 0.666, 'precision': 'precise', 'match_types': ['point_of_interest']} # TODO: wrong } METADATAS = {