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

pull/343/head
Karl Hobley 2014-06-20 11:42:17 +01:00
rodzic 16b385da97
commit 1475d440e3
1 zmienionych plików z 2 dodań i 2 usunięć

Wyświetl plik

@ -173,7 +173,7 @@ class ElasticSearchResults(object):
# Return results in order given by ElasticSearch # Return results in order given by ElasticSearch
return [results[str(pk)] for pk in pks if results[str(pk)]] return [results[str(pk)] for pk in pks if results[str(pk)]]
def _do_count(self): def count(self):
# Get query # Get query
query = self.query.to_es() query = self.query.to_es()
@ -219,7 +219,7 @@ class ElasticSearchResults(object):
return iter(self._do_search()) return iter(self._do_search())
def __len__(self): def __len__(self):
return self._do_count() return len(self._do_search())
class ElasticSearch(BaseSearch): class ElasticSearch(BaseSearch):