From b1105e8ac5f08318ef87d46ce0ad22788fb96444 Mon Sep 17 00:00:00 2001 From: dojutsu-user Date: Mon, 15 Jul 2019 13:40:08 +0530 Subject: [PATCH] override count method --- readthedocs/search/faceted_search.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/readthedocs/search/faceted_search.py b/readthedocs/search/faceted_search.py index 9fed27de679..673a4fe6948 100644 --- a/readthedocs/search/faceted_search.py +++ b/readthedocs/search/faceted_search.py @@ -99,6 +99,16 @@ class PageSearchBase(RTDFacetedSearch): fields = ['title^10', 'headers^5', 'content'] operators = ['and', 'or'] + def count(self): + """Overriding ``count`` method to return the count of the results after post_filter.""" + s = self.build_search() + + # setting size=0 so that no results are returned, + # we are only interested in the total count + s = s.extra(size=0) + s = s.execute() + return s.hits.total + class DomainSearchBase(RTDFacetedSearch): facets = {