Skip to content

Commit a591e9d

Browse files
cleanup
1 parent 5e0ebe4 commit a591e9d

File tree

3 files changed

+2
-270
lines changed

3 files changed

+2
-270
lines changed

.hgignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ syntax: regexp
1919
^var/
2020
^releases/
2121
^demo/
22+
^codebin/
2223
^deploy/
2324
^examples/db/
2425
^examples/tmp/

src/django_elasticsearch_dsl_drf/constants.py

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@
1616
'FALSE_VALUES',
1717
'LOOKUP_FILTER_EXISTS',
1818
'LOOKUP_FILTER_GEO_DISTANCE',
19-
'LOOKUP_FILTER_GEO_DISTANCE_FROM',
20-
'LOOKUP_FILTER_GEO_DISTANCE_GT',
21-
'LOOKUP_FILTER_GEO_DISTANCE_GTE',
22-
'LOOKUP_FILTER_GEO_DISTANCE_INCLUDE_LOWER',
23-
'LOOKUP_FILTER_GEO_DISTANCE_INCLUDE_UPPER',
24-
'LOOKUP_FILTER_GEO_DISTANCE_LT',
25-
'LOOKUP_FILTER_GEO_DISTANCE_LTE',
26-
'LOOKUP_FILTER_GEO_DISTANCE_RANGE',
27-
'LOOKUP_FILTER_GEO_DISTANCE_TO',
2819
'LOOKUP_FILTER_GEO_POLYGON',
2920
'LOOKUP_FILTER_PREFIX',
3021
'LOOKUP_FILTER_RANGE',
@@ -231,78 +222,6 @@
231222
# /api/articles/?location__geo_distance=2km|43.53455243|-12.2344243
232223
LOOKUP_FILTER_GEO_DISTANCE = 'geo_distance'
233224

234-
# Geo-distance range filters support the same point location parameter and
235-
# query options as the geo_distance filter. And also support the common
236-
# parameters for range (lt, lte, gt, gte, from, to, include_upper and
237-
# include_lower).
238-
#
239-
# The geo-distance range filter.
240-
# Filters documents that exists within a range from a specific point.
241-
# Example:
242-
# {
243-
# "query": {
244-
# "bool" : {
245-
# "must" : {
246-
# "match_all" : {}
247-
# },
248-
# "filter" : {
249-
# "geo_distance_range" : {
250-
# "from" : "200km",
251-
# "to" : "400km",
252-
# "pin.location" : {
253-
# "lat" : 40,
254-
# "lon" : -70
255-
# }
256-
# }
257-
# }
258-
# }
259-
# }
260-
# }
261-
#
262-
# Example: http://localhost:8000
263-
# /api/articles/?location__geo_distance_range=2km|10km|43.53455243|-12.2344243
264-
LOOKUP_FILTER_GEO_DISTANCE_RANGE = 'geo_distance_range'
265-
266-
# The geo-distance gt filter.
267-
# Example: http://localhost:8000
268-
# /api/articles/?location__geo_distance_gt=2km|43.53455243|-12.2344243
269-
LOOKUP_FILTER_GEO_DISTANCE_GT = 'geo_distance_gt'
270-
271-
# The geo-distance gte filter.
272-
# Example: http://localhost:8000
273-
# /api/articles/?location__geo_distance_gte=2km|43.53455243|-12.2344243
274-
LOOKUP_FILTER_GEO_DISTANCE_GTE = 'geo_distance_gte'
275-
276-
# The geo-distance lt filter.
277-
# Example: http://localhost:8000
278-
# /api/articles/?location__geo_distance_lt=2km|43.53455243|-12.2344243
279-
LOOKUP_FILTER_GEO_DISTANCE_LT = 'geo_distance_lt'
280-
281-
# The geo-distance lte filter.
282-
# Example: http://localhost:8000
283-
# /api/articles/?location__geo_distance_lte=2km|43.53455243|-12.2344243
284-
LOOKUP_FILTER_GEO_DISTANCE_LTE = 'geo_distance_lte'
285-
286-
# The geo-distance from filter (alias of gt).
287-
# Example: http://localhost:8000
288-
# /api/articles/?location__geo_distance_from=2km|43.53455243|-12.2344243
289-
LOOKUP_FILTER_GEO_DISTANCE_FROM = 'geo_distance_from'
290-
291-
# The geo-distance to filter (alias of lt).
292-
# Example: http://localhost:8000
293-
# /api/articles/?location__geo_distance_to=2km|43.53455243|-12.2344243
294-
LOOKUP_FILTER_GEO_DISTANCE_TO = 'geo_distance_to'
295-
296-
# The geo-distance include_upper filter (alias of lte).
297-
# Example: http://localhost:8000
298-
# /api/articles/?location__geo_distance_include_upper=2km|43.53|-12.23
299-
LOOKUP_FILTER_GEO_DISTANCE_INCLUDE_UPPER = 'geo_distance_include_upper'
300-
301-
# The geo-distance include_lower filter (alias of gte).
302-
# Example: http://localhost:8000
303-
# /api/articles/?location__geo_distance_include_lower=2km|43.53|-12.23
304-
LOOKUP_FILTER_GEO_DISTANCE_INCLUDE_LOWER = 'geo_distance_include_lower'
305-
306225
# Geo Polygon Query
307226
#
308227
# A query allowing to include hits that only fall within a polygon of points.
@@ -454,15 +373,7 @@
454373

455374
ALL_GEO_SPATIAL_LOOKUP_FILTERS_AND_QUERIES = (
456375
LOOKUP_FILTER_GEO_DISTANCE,
457-
LOOKUP_FILTER_GEO_DISTANCE_RANGE,
458-
LOOKUP_FILTER_GEO_DISTANCE_GT,
459-
LOOKUP_FILTER_GEO_DISTANCE_GTE,
460-
LOOKUP_FILTER_GEO_DISTANCE_LT,
461-
LOOKUP_FILTER_GEO_DISTANCE_LTE,
462-
LOOKUP_FILTER_GEO_DISTANCE_FROM,
463-
LOOKUP_FILTER_GEO_DISTANCE_TO,
464-
LOOKUP_FILTER_GEO_DISTANCE_INCLUDE_UPPER,
465-
LOOKUP_FILTER_GEO_DISTANCE_INCLUDE_LOWER,
376+
LOOKUP_FILTER_GEO_POLYGON,
466377
)
467378

468379
STRING_LOOKUP_FILTERS = [

src/django_elasticsearch_dsl_drf/filter_backends/filtering/geo_spatial.py

Lines changed: 0 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -236,96 +236,6 @@ def get_geo_polygon_params(cls, value, field):
236236
return params
237237
return {}
238238

239-
@classmethod
240-
def get_range_params(cls, value, field):
241-
"""Get params for `range` query.
242-
243-
Example:
244-
245-
/api/articles/?location__geo_distance_range=2km|10km|43.53|-12.23
246-
247-
Elasticsearch query:
248-
249-
{
250-
"query": {
251-
"bool" : {
252-
"must" : {
253-
"match_all" : {}
254-
},
255-
"filter" : {
256-
"geo_distance_range" : {
257-
"from" : "200km",
258-
"to" : "400km",
259-
"pin.location" : {
260-
"lat" : 40,
261-
"lon" : -70
262-
}
263-
}
264-
}
265-
}
266-
}
267-
}
268-
269-
:param value:
270-
:param field:
271-
:type: str
272-
:type: str
273-
:return: Params to be used in `range` query.
274-
:rtype: dict
275-
"""
276-
__values = cls.split_lookup_value(value, maxsplit=4)
277-
__len_values = len(__values)
278-
279-
if __len_values < 4:
280-
return {}
281-
282-
params = {
283-
'from': __values[0],
284-
'to': __values[1],
285-
field: {
286-
'lat': __values[2],
287-
'lon': __values[3]
288-
}
289-
}
290-
291-
return params
292-
293-
@classmethod
294-
def get_gte_lte_params(cls, value, lookup, field):
295-
"""Get params for `gte`, `gt`, `lte` and `lt` query.
296-
297-
Examples:
298-
299-
/api/articles/?location__geo_distance_gt=2km|43.53|-12.23
300-
/api/articles/?location__geo_distance_gte=2km|43.53|-12.23
301-
/api/articles/?location__geo_distance_lt=2km|43.53|-12.23
302-
/api/articles/?location__geo_distance_lte=2km|43.53|-12.23
303-
304-
:param value:
305-
:param lookup:
306-
:param field:
307-
:type value: str
308-
:type lookup: str
309-
:type field: str
310-
:return: Params to be used in `range` query.
311-
:rtype: dict
312-
"""
313-
__values = cls.split_lookup_value(value, maxsplit=3)
314-
__len_values = len(__values)
315-
316-
if __len_values < 3:
317-
return {}
318-
319-
params = {
320-
lookup: __values[0],
321-
field: {
322-
'lat': __values[2],
323-
'lon': __values[3]
324-
}
325-
}
326-
327-
return params
328-
329239
@classmethod
330240
def apply_query_geo_distance(cls, queryset, options, value):
331241
"""Apply `geo_distance` query.
@@ -346,96 +256,6 @@ def apply_query_geo_distance(cls, queryset, options, value):
346256
)
347257
)
348258

349-
@classmethod
350-
def apply_query_geo_distance_range(cls, queryset, options, value):
351-
"""Apply `geo_distance_range` `range` query.
352-
353-
:param queryset: Original queryset.
354-
:param options: Filter options.
355-
:param value: value to filter on.
356-
:type queryset: elasticsearch_dsl.search.Search
357-
:type options: dict
358-
:type value: str
359-
:return: Modified queryset.
360-
:rtype: elasticsearch_dsl.search.Search
361-
"""
362-
return queryset.filter(
363-
'geo_distance_range',
364-
**cls.get_range_params(value, options['field'])
365-
)
366-
367-
@classmethod
368-
def apply_query_geo_distance_gt(cls, queryset, options, value):
369-
"""Apply `geo_distance_range` `gt` query.
370-
371-
:param queryset: Original queryset.
372-
:param options: Filter options.
373-
:param value: value to filter on.
374-
:type queryset: elasticsearch_dsl.search.Search
375-
:type options: dict
376-
:type value: str
377-
:return: Modified queryset.
378-
:rtype: elasticsearch_dsl.search.Search
379-
"""
380-
return queryset.filter(
381-
'geo_distance_range',
382-
**cls.get_gte_lte_params(value, 'gt', options['field'])
383-
)
384-
385-
@classmethod
386-
def apply_query_geo_distance_gte(cls, queryset, options, value):
387-
"""Apply `geo_distance_range` `gte` query.
388-
389-
:param queryset: Original queryset.
390-
:param options: Filter options.
391-
:param value: value to filter on.
392-
:type queryset: elasticsearch_dsl.search.Search
393-
:type options: dict
394-
:type value: str
395-
:return: Modified queryset.
396-
:rtype: elasticsearch_dsl.search.Search
397-
"""
398-
return queryset.filter(
399-
'geo_distance_range',
400-
**cls.get_gte_lte_params(value, 'gte', options['field'])
401-
)
402-
403-
@classmethod
404-
def apply_query_geo_distance_lt(cls, queryset, options, value):
405-
"""Apply `geo_distance_range` `lt` query.
406-
407-
:param queryset: Original queryset.
408-
:param options: Filter options.
409-
:param value: value to filter on.
410-
:type queryset: elasticsearch_dsl.search.Search
411-
:type options: dict
412-
:type value: str
413-
:return: Modified queryset.
414-
:rtype: elasticsearch_dsl.search.Search
415-
"""
416-
return queryset.filter(
417-
'geo_distance_range',
418-
**cls.get_gte_lte_params(value, 'lt', options['field'])
419-
)
420-
421-
@classmethod
422-
def apply_query_geo_distance_lte(cls, queryset, options, value):
423-
"""Apply `geo_distance_range` `lte` query.
424-
425-
:param queryset: Original queryset.
426-
:param options: Filter options.
427-
:param value: value to filter on.
428-
:type queryset: elasticsearch_dsl.search.Search
429-
:type options: dict
430-
:type value: str
431-
:return: Modified queryset.
432-
:rtype: elasticsearch_dsl.search.Search
433-
"""
434-
return queryset.filter(
435-
'geo_distance_range',
436-
**cls.get_gte_lte_params(value, 'lte', options['field'])
437-
)
438-
439259
@classmethod
440260
def apply_query_geo_polygon(cls, queryset, options, value):
441261
"""Apply `geo_polygon` query.

0 commit comments

Comments
 (0)