maps: evaluate query against subproperties (#26422)

This commit is contained in:
Frédéric Péters 2018-09-14 14:51:09 +02:00
parent f872cafd75
commit fab379d739
2 changed files with 21 additions and 5 deletions

View File

@ -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

View File

@ -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