diff --git a/combo/apps/maps/models.py b/combo/apps/maps/models.py index 479d0cda..a3ee88f9 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..d7ee39c0 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": { + "plop": "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