Skip to content

Commit e97c858

Browse files
committed
Update Regexp Field Lookup Implementation
1 parent e0e37cc commit e97c858

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

src/django_elasticsearch_dsl_drf/constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@
434434
LOOKUP_FILTER_EXISTS,
435435
LOOKUP_FILTER_PREFIX,
436436
LOOKUP_FILTER_WILDCARD,
437-
# LOOKUP_FILTER_REGEXP,
437+
LOOKUP_FILTER_REGEXP,
438438
# LOOKUP_FILTER_FUZZY,
439439
# LOOKUP_FILTER_TYPE,
440440

@@ -475,6 +475,7 @@
475475
LOOKUP_FILTER_TERMS,
476476
LOOKUP_FILTER_PREFIX,
477477
LOOKUP_FILTER_WILDCARD,
478+
LOOKUP_FILTER_REGEXP,
478479
LOOKUP_QUERY_CONTAINS,
479480
LOOKUP_QUERY_IN,
480481
LOOKUP_QUERY_STARTSWITH,

src/django_elasticsearch_dsl_drf/filter_backends/filtering/common.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,18 +296,16 @@ def apply_filter_range(cls, queryset, options, value):
296296

297297
@classmethod
298298
def apply_filter_regexp(cls, queryset, options, value):
299-
"""Apply `regexp` filter.
299+
"""Apply `reexp` filter.
300300
301301
Syntax:
302302
303-
/endpoint/?field_name__regexp={lower}__{upper}__{boost}
304-
/endpoint/?field_name__regexp={lower}__{upper}
303+
/endpoint/?field_name__regexp={regexp}
305304
306305
Example:
307306
308-
http://localhost:8000/api/users/?age__regexp=16__67__2.0
309-
http://localhost:8000/api/users/?age__regexp=16__67
310-
http://localhost:8000/api/users/?age__regexp=16
307+
http://localhost:8000/api/users/?age__regexp=1[6-9]
308+
http://localhost:8000/api/users/?age__regexp=2.*
311309
312310
:param queryset: Original queryset.
313311
:param options: Filter options.

src/django_elasticsearch_dsl_drf/tests/test_filtering_common.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,19 @@ def test_field_filter_range(self):
193193
self.published_count
194194
)
195195

196+
def test_field_filter_regexp(self):
197+
"""Field filter regexp.
198+
199+
Example:
200+
201+
http://localhost:8000/api/users/?title__regexp=De.{8}Ins.*
202+
"""
203+
return self._field_filter_value(
204+
'title__regexp',
205+
'{}.{{8}}{}.*'.format(self.prefix[0:2], self.prefix[10:13]),
206+
self.prefix_count
207+
)
208+
196209
def test_field_filter_range_with_boost(self):
197210
"""Field filter range.
198211
@@ -325,19 +338,6 @@ def test_field_filter_wildcard(self):
325338
self.prefix_count
326339
)
327340

328-
def test_field_filter_regexp(self):
329-
"""Test filter regexp.
330-
331-
Example:
332-
333-
http://localhost:8000/api/articles/?title__wildcard=*elusional*
334-
"""
335-
return self._field_filter_value(
336-
'title__regexp',
337-
'.{2}lusional.{2}sanity\s.*',
338-
self.prefix_count
339-
)
340-
341341
def test_field_filter_exclude(self):
342342
"""Test filter exclude.
343343

0 commit comments

Comments
 (0)