File tree Expand file tree Collapse file tree 4 files changed +19
-9
lines changed Expand file tree Collapse file tree 4 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -666,8 +666,8 @@ def count(self):
666
666
Return the number of hits matching the query and filters. Note that
667
667
only the actual number is returned.
668
668
"""
669
- if hasattr (self , '_response' ):
670
- return self ._response .hits .total
669
+ if hasattr (self , '_response' ) and self . _response . hits . total . relation == 'eq' :
670
+ return self ._response .hits .total . value
671
671
672
672
es = connections .get_connection (self ._using )
673
673
Original file line number Diff line number Diff line change 22
22
"mock" ,
23
23
"pytest>=3.0.0" ,
24
24
"pytest-cov" ,
25
+ "pytest-mock" ,
25
26
"pytz" ,
26
27
"coverage<5.0.0"
27
28
]
Original file line number Diff line number Diff line change 1
1
from elasticsearch_dsl .search import Search , Q
2
2
3
+
3
4
def test_count_all (data_client ):
4
5
s = Search (using = data_client ).index ('git' )
5
6
assert 53 == s .count ()
6
7
8
+
9
+ def test_count_prefetch (data_client , mocker ):
10
+ mocker .spy (data_client , 'count' )
11
+
12
+ search = Search (using = data_client ).index ('git' )
13
+ search .execute ()
14
+ assert search .count () == 53
15
+ assert data_client .count .call_count == 0
16
+
17
+ search ._response .hits .total .relation = 'gte'
18
+ assert search .count () == 53
19
+ assert data_client .count .call_count == 1
20
+
21
+
7
22
def test_count_filter (data_client ):
8
23
s = Search (using = data_client ).index ('git' ).filter (~ Q ('exists' , field = 'parent_shas' ))
9
24
# initial commit + repo document
Original file line number Diff line number Diff line change @@ -35,12 +35,6 @@ def test_iter_iterates_over_hits():
35
35
36
36
assert [1 , 2 , 3 ] == list (s )
37
37
38
- def test_count_uses_cache ():
39
- s = search .Search ()
40
- s ._response = utils .AttrDict ({'hits' : {'total' : 42 }})
41
-
42
- assert 42 == s .count ()
43
-
44
38
def test_cache_isnt_cloned ():
45
39
s = search .Search ()
46
40
s ._response = object ()
@@ -544,4 +538,4 @@ def test_update_from_dict():
544
538
'id' ,
545
539
'name'
546
540
]
547
- } == s .to_dict ()
541
+ } == s .to_dict ()
You can’t perform that action at this time.
0 commit comments