Skip to content

Commit 7e112c1

Browse files
authored
Merge pull request #5926 from dojutsu-user/results-total-hack
Fix count value of docsearch REST api
2 parents e12f70d + b1105e8 commit 7e112c1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

readthedocs/search/faceted_search.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ class PageSearchBase(RTDFacetedSearch):
9999
fields = ['title^10', 'headers^5', 'content']
100100
operators = ['and', 'or']
101101

102+
def count(self):
103+
"""Overriding ``count`` method to return the count of the results after post_filter."""
104+
s = self.build_search()
105+
106+
# setting size=0 so that no results are returned,
107+
# we are only interested in the total count
108+
s = s.extra(size=0)
109+
s = s.execute()
110+
return s.hits.total
111+
102112

103113
class DomainSearchBase(RTDFacetedSearch):
104114
facets = {

0 commit comments

Comments
 (0)