Skip to content

Commit f701dbe

Browse files
committed
geo_shape queries: Add test for circle intersects
1 parent 646714f commit f701dbe

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

examples/simple/books/models/publisher.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,23 @@ def location_field_indexing(self):
5252

5353
@property
5454
def location_shape_indexing(self):
55-
"""Location for indexing.
56-
55+
"""
56+
Indexing point geo_shape.
5757
Used in Elasticsearch indexing/tests of `geo_shape` native filter.
5858
"""
5959
return {
6060
'type': 'point',
6161
'coordinates': [self.latitude, self.longitude],
6262
}
63+
64+
@property
65+
def location_circle_indexing(self):
66+
"""
67+
Indexing circle geo_shape with 10km radius.
68+
Used in Elasticsearch indexing/tests of `geo_shape` native filter.
69+
"""
70+
return {
71+
'type': 'circle',
72+
'coordinates': [self.latitude, self.longitude],
73+
'radius': '10km',
74+
}

examples/simple/search_indexes/documents/publisher.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class PublisherDocument(Document):
8080

8181
location_shape = fields.GeoShapeField(strategy='recursive',
8282
attr='location_shape_indexing')
83+
location_circle = fields.GeoShapeField(strategy='recursive',
84+
attr='location_circle_indexing')
8385

8486
class Django(object):
8587
model = Publisher # The model associate with this Document

src/django_elasticsearch_dsl_drf/tests/test_filtering_geo_spatial.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ def _test_field_filter_geo_shape(self, points, count, gs_coordinates, gs_relatio
444444
__params
445445
)
446446

447+
print(url)
447448
publishers = []
448449
for __lat, __lon in points:
449450
publishers.append(
@@ -491,22 +492,44 @@ def test_field_filter_geo_shape_circle(self):
491492
492493
:return:
493494
"""
494-
valid_points = [
495+
points = [
495496
(49.0999832, 6.153041),
496497
(49.061012, 6.1529298),
497498
# outside circle
498499
(48.6937223, 6.1834097),
499500
]
500501

501502
return self._test_field_filter_geo_shape(
502-
points=valid_points,
503+
points=points,
503504
count=2,
504505
gs_coordinates=[['49.119696', '6.176355']],
505506
gs_relation='within',
506507
gs_type='circle',
507508
gs_extra='radius,10km',
508509
)
509510

511+
@pytest.mark.webtest
512+
def test_field_filter_geo_shape_circle_intersects(self):
513+
"""Test field filter geo-shape.
514+
515+
:return:
516+
"""
517+
points = [
518+
# intersects with query's circle
519+
(48.584614, 7.7507127),
520+
# do not intersects with query's circle
521+
(48.5419351, 7.4924679),
522+
]
523+
524+
return self._test_field_filter_geo_shape(
525+
points=points,
526+
count=1,
527+
gs_coordinates=[['48.5728929', '7.8109768']],
528+
gs_relation='intersects',
529+
gs_type='circle',
530+
gs_extra='radius,10km',
531+
)
532+
510533

511534
if __name__ == '__main__':
512535
unittest.main()

0 commit comments

Comments
 (0)