Skip to content

Commit 78c665c

Browse files
committed
Fix by imported the supported class, otherwise fallback to original implementation
1 parent d83900f commit 78c665c

File tree

1 file changed

+29
-25
lines changed
  • src/django_elasticsearch_dsl_drf

1 file changed

+29
-25
lines changed

src/django_elasticsearch_dsl_drf/utils.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
import datetime
6-
from elasticsearch_dsl.search import AggsProxy
76

87

98
__title__ = 'django_elasticsearch_dsl_drf.utils'
@@ -15,40 +14,45 @@
1514
'EmptySearch',
1615
)
1716

17+
try:
18+
# code for 8.13 (requires 8.13.1)
19+
from elasticsearch_dsl import EmptySearch
20+
except ImportError:
21+
from elasticsearch_dsl.search import AggsProxy
1822

19-
class EmptySearch(object):
20-
"""Empty Search."""
23+
class EmptySearch(object):
24+
"""Empty Search."""
2125

22-
def __init__(self, *args, **kwargs):
23-
self.aggs = AggsProxy('')
24-
self._highlight = {}
25-
self._sort = []
26-
self.total = 0
26+
def __init__(self, *args, **kwargs):
27+
self.aggs = AggsProxy('')
28+
self._highlight = {}
29+
self._sort = []
30+
self.total = 0
2731

28-
def __len__(self):
29-
return 0
32+
def __len__(self):
33+
return 0
3034

31-
def __iter__(self):
32-
return iter([])
35+
def __iter__(self):
36+
return iter([])
3337

34-
def __getitem__(self, *args, **kwargs):
35-
return self
38+
def __getitem__(self, *args, **kwargs):
39+
return self
3640

37-
def highlight(self, *args, **kwargs):
38-
return self
41+
def highlight(self, *args, **kwargs):
42+
return self
3943

40-
def sort(self, *args, **kwargs):
41-
return self
44+
def sort(self, *args, **kwargs):
45+
return self
4246

43-
@property
44-
def hits(self):
45-
return self
47+
@property
48+
def hits(self):
49+
return self
4650

47-
def execute(self, *args, **kwargs):
48-
return self
51+
def execute(self, *args, **kwargs):
52+
return self
4953

50-
def to_dict(self, *args, **kwargs):
51-
return {}
54+
def to_dict(self, *args, **kwargs):
55+
return {}
5256

5357

5458
class DictionaryProxy(object):

0 commit comments

Comments
 (0)