From 1475d440e3b5a38eb9ff4a939b7bce4fcc1d0850 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Fri, 20 Jun 2014 11:42:17 +0100 Subject: [PATCH] len(ESResults) now runs query and gets the length of the results. Added ESResults.count() which asks Elasticsearch for the count but doesn't run the query --- wagtail/wagtailsearch/backends/elasticsearch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wagtail/wagtailsearch/backends/elasticsearch.py b/wagtail/wagtailsearch/backends/elasticsearch.py index 6bd48aafe8..5f62b96a87 100644 --- a/wagtail/wagtailsearch/backends/elasticsearch.py +++ b/wagtail/wagtailsearch/backends/elasticsearch.py @@ -173,7 +173,7 @@ class ElasticSearchResults(object): # Return results in order given by ElasticSearch return [results[str(pk)] for pk in pks if results[str(pk)]] - def _do_count(self): + def count(self): # Get query query = self.query.to_es() @@ -219,7 +219,7 @@ class ElasticSearchResults(object): return iter(self._do_search()) def __len__(self): - return self._do_count() + return len(self._do_search()) class ElasticSearch(BaseSearch):