From 6271ac17c1754a8bb93b3ae16ecd7b81c71556d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 14 Sep 2018 14:51:09 +0200 Subject: [PATCH] maps: evaluate query against subproperties (#26422) --- combo/apps/maps/models.py | 17 +++++++++++++---- tests/test_maps_cells.py | 9 ++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/combo/apps/maps/models.py b/combo/apps/maps/models.py index 3a8ae69d..9a54c795 100644 --- a/combo/apps/maps/models.py +++ b/combo/apps/maps/models.py @@ -212,11 +212,20 @@ class MapLayer(models.Model): def match(feature): matching_query_words = set() - for geo_property in feature['properties'].values() + additional_strings: - if not isinstance(geo_property, six.string_types): - continue + feature_words = additional_strings[:] + + def get_feature_words(properties): + for property in properties.values(): + if isinstance(property, six.string_types): + feature_words.append(property) + elif isinstance(property, dict): + get_feature_words(property) + + get_feature_words(feature['properties']) + + for feature_word in feature_words: for word in query_words: - if word in slugify(geo_property): + if word in slugify(feature_word): matching_query_words.add(word) if len(matching_query_words) == len(query_words): return True diff --git a/tests/test_maps_cells.py b/tests/test_maps_cells.py index 5e385570..2f5fafa5 100644 --- a/tests/test_maps_cells.py +++ b/tests/test_maps_cells.py @@ -36,7 +36,10 @@ SAMPLE_GEOJSON_CONTENT = '''{ "type": "Feature", "properties": { "name": "Bar", - "extra": "Baz" + "extra": "Baz", + "subdict": { + "whatever": "Whatever" + } }, "geometry": { "type": "Point", @@ -262,6 +265,10 @@ def test_get_geojson(app, layer, user): resp = app.get(reverse('mapcell-geojson', kwargs={'cell_id': cell.id}) + '?q=bicycle') assert len(json.loads(resp.content)['features']) == 0 + # query against subproperty + resp = app.get(reverse('mapcell-geojson', kwargs={'cell_id': cell.id}) + '?q=whatever') + assert len(json.loads(resp.content)['features']) == 1 + # check distance query on geojson layer.geojson_url = 'http://example.org/geojson?t6' layer.include_user_identifier = False -- 2.19.0