Added support for $maxDistance (#179)
This commit is contained in:
parent
0b177ec4c1
commit
2c7b12c022
@ -27,6 +27,7 @@ Changes in 0.8.X
|
|||||||
- Simplified Q objects, removed QueryTreeTransformerVisitor (#98) (#171)
|
- Simplified Q objects, removed QueryTreeTransformerVisitor (#98) (#171)
|
||||||
- FileFields now copyable (#198)
|
- FileFields now copyable (#198)
|
||||||
- Querysets now return clones and are no longer edit in place (#56)
|
- Querysets now return clones and are no longer edit in place (#56)
|
||||||
|
- Added support for $maxDistance (#179)
|
||||||
|
|
||||||
Changes in 0.7.9
|
Changes in 0.7.9
|
||||||
================
|
================
|
||||||
|
@ -92,6 +92,8 @@ may used with :class:`~mongoengine.GeoPointField`\ s:
|
|||||||
* ``within_polygon`` -- filter documents to those within a given polygon (e.g.
|
* ``within_polygon`` -- filter documents to those within a given polygon (e.g.
|
||||||
[(41.91,-87.69), (41.92,-87.68), (41.91,-87.65), (41.89,-87.65)]).
|
[(41.91,-87.69), (41.92,-87.68), (41.91,-87.65), (41.89,-87.65)]).
|
||||||
.. note:: Requires Mongo Server 2.0
|
.. note:: Requires Mongo Server 2.0
|
||||||
|
* ``max_distance`` -- can be added to your location queries to set a maximum
|
||||||
|
distance.
|
||||||
|
|
||||||
|
|
||||||
Querying lists
|
Querying lists
|
||||||
|
@ -9,7 +9,8 @@ __all__ = ('query', 'update')
|
|||||||
COMPARISON_OPERATORS = ('ne', 'gt', 'gte', 'lt', 'lte', 'in', 'nin', 'mod',
|
COMPARISON_OPERATORS = ('ne', 'gt', 'gte', 'lt', 'lte', 'in', 'nin', 'mod',
|
||||||
'all', 'size', 'exists', 'not')
|
'all', 'size', 'exists', 'not')
|
||||||
GEO_OPERATORS = ('within_distance', 'within_spherical_distance',
|
GEO_OPERATORS = ('within_distance', 'within_spherical_distance',
|
||||||
'within_box', 'within_polygon', 'near', 'near_sphere')
|
'within_box', 'within_polygon', 'near', 'near_sphere',
|
||||||
|
'max_distance')
|
||||||
STRING_OPERATORS = ('contains', 'icontains', 'startswith',
|
STRING_OPERATORS = ('contains', 'icontains', 'startswith',
|
||||||
'istartswith', 'endswith', 'iendswith',
|
'istartswith', 'endswith', 'iendswith',
|
||||||
'exact', 'iexact')
|
'exact', 'iexact')
|
||||||
@ -97,6 +98,8 @@ def query(_doc_cls=None, _field_operation=False, **query):
|
|||||||
value = {'$nearSphere': value}
|
value = {'$nearSphere': value}
|
||||||
elif op == 'within_box':
|
elif op == 'within_box':
|
||||||
value = {'$within': {'$box': value}}
|
value = {'$within': {'$box': value}}
|
||||||
|
elif op == "max_distance":
|
||||||
|
value = {'$maxDistance': value}
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("Geo method '%s' has not "
|
raise NotImplementedError("Geo method '%s' has not "
|
||||||
"been implemented" % op)
|
"been implemented" % op)
|
||||||
|
@ -2238,6 +2238,12 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
self.assertEqual(events.count(), 3)
|
self.assertEqual(events.count(), 3)
|
||||||
self.assertEqual(list(events), [event3, event1, event2])
|
self.assertEqual(list(events), [event3, event1, event2])
|
||||||
|
|
||||||
|
# find events within 10 degrees of san francisco
|
||||||
|
point = [37.7566023, -122.415579]
|
||||||
|
events = Event.objects(location__near=point, location__max_distance=10)
|
||||||
|
self.assertEqual(events.count(), 1)
|
||||||
|
self.assertEqual(events[0], event2)
|
||||||
|
|
||||||
# find events within 10 degrees of san francisco
|
# find events within 10 degrees of san francisco
|
||||||
point_and_distance = [[37.7566023, -122.415579], 10]
|
point_and_distance = [[37.7566023, -122.415579], 10]
|
||||||
events = Event.objects(location__within_distance=point_and_distance)
|
events = Event.objects(location__within_distance=point_and_distance)
|
||||||
@ -2317,6 +2323,10 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
);
|
);
|
||||||
self.assertEqual(points.count(), 2)
|
self.assertEqual(points.count(), 2)
|
||||||
|
|
||||||
|
points = Point.objects(location__near_sphere=[-122, 37.5],
|
||||||
|
location__max_distance=60 / earth_radius);
|
||||||
|
self.assertEqual(points.count(), 2)
|
||||||
|
|
||||||
# Finds both points, but orders the north point first because it's
|
# Finds both points, but orders the north point first because it's
|
||||||
# closer to the reference point to the north.
|
# closer to the reference point to the north.
|
||||||
points = Point.objects(location__near_sphere=[-122, 38.5])
|
points = Point.objects(location__near_sphere=[-122, 38.5])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user