0001-maps-evaluate-query-against-subproperties-26422.patch
combo/apps/maps/models.py | ||
---|---|---|
212 | 212 | |
213 | 213 |
def match(feature): |
214 | 214 |
matching_query_words = set() |
215 |
for geo_property in feature['properties'].values() + additional_strings: |
|
216 |
if not isinstance(geo_property, six.string_types): |
|
217 |
continue |
|
215 |
feature_words = additional_strings[:] |
|
216 | ||
217 |
def get_feature_words(properties): |
|
218 |
for property in properties.values(): |
|
219 |
if isinstance(property, six.string_types): |
|
220 |
feature_words.append(property) |
|
221 |
elif isinstance(property, dict): |
|
222 |
get_feature_words(property) |
|
223 | ||
224 |
get_feature_words(feature['properties']) |
|
225 | ||
226 |
for feature_word in feature_words: |
|
218 | 227 |
for word in query_words: |
219 |
if word in slugify(geo_property):
|
|
228 |
if word in slugify(feature_word):
|
|
220 | 229 |
matching_query_words.add(word) |
221 | 230 |
if len(matching_query_words) == len(query_words): |
222 | 231 |
return True |
tests/test_maps_cells.py | ||
---|---|---|
36 | 36 |
"type": "Feature", |
37 | 37 |
"properties": { |
38 | 38 |
"name": "Bar", |
39 |
"extra": "Baz" |
|
39 |
"extra": "Baz", |
|
40 |
"subdict": { |
|
41 |
"whatever": "Whatever" |
|
42 |
} |
|
40 | 43 |
}, |
41 | 44 |
"geometry": { |
42 | 45 |
"type": "Point", |
... | ... | |
262 | 265 |
resp = app.get(reverse('mapcell-geojson', kwargs={'cell_id': cell.id}) + '?q=bicycle') |
263 | 266 |
assert len(json.loads(resp.content)['features']) == 0 |
264 | 267 | |
268 |
# query against subproperty |
|
269 |
resp = app.get(reverse('mapcell-geojson', kwargs={'cell_id': cell.id}) + '?q=whatever') |
|
270 |
assert len(json.loads(resp.content)['features']) == 1 |
|
271 | ||
265 | 272 |
# check distance query on geojson |
266 | 273 |
layer.geojson_url = 'http://example.org/geojson?t6' |
267 | 274 |
layer.include_user_identifier = False |
268 |
- |