Permalink
Browse files

Switch .all() to .everything()

* switch the old .all() to .everything()
* change .all() to be more like what Django ModelManager/QuerySet does

Fixes #200
  • Loading branch information...
1 parent b40d68a commit 58ccf86c017a9f06858e75f55fd7d9e455c03d8a @willkg willkg committed Feb 28, 2014
Showing with 27 additions and 8 deletions.
  1. +7 −0 CHANGELOG
  2. +1 −1 docs/searching.rst
  3. +13 −6 elasticutils/__init__.py
  4. +6 −1 elasticutils/tests/test_query.py
View
@@ -68,9 +68,16 @@ Version 0.9: In development
and for most things, there's a 1-to-1 translation. Also, in many cases
it's cleaner, so you'll probably be removing code.
+* **.all() no longer returns all results**
+
+ If you were using `.all()` to return all search results, you should
+ change it to `.everything()`.
+
**Changes:**
+* **added .everything() which does what .all() did**
+
* **index_objects celery task can now take es and index args**
* **unindex_objects celery task can now take es and index args**
View
@@ -125,7 +125,7 @@ The search won't execute until you do one of the following:
1. use the :py:class:`elasticutils.S` in an iterable context
2. call :py:func:`len` on a :py:class:`elasticutils.S`
3. call the :py:meth:`elasticutils.S.execute`,
- :py:meth:`elasticutils.S.all`,
+ :py:meth:`elasticutils.S.everything`,
:py:meth:`elasticutils.S.count`,
:py:meth:`elasticutils.S.suggestions` or
:py:meth:`elasticutils.S.facet_counts` methods
View
@@ -1481,22 +1481,29 @@ def __len__(self):
return len(self._do_search())
def all(self):
+ """No-op that returns a clone of self
+
+ This is here to make it more Django QuerySet-like and work
+ with better with things that accept QuerySets.
"""
- Executes search and returns ALL search results.
+ return self._clone()
+
+ def everything(self):
+ """Executes search and returns ALL search results.
:returns: `SearchResults` instance
For example:
>>> s = S().query(name__prefix='Jimmy')
- >>> all_results = s.all()
+ >>> all_results = s.everything()
.. Warning::
- This returns ALL search results. The way it does this is by
- calling ``.count()`` first to figure out how many to return,
- then by slicing by that size and returning a list of ALL
- search results.
+ This returns ALL possible search results. The way it does
+ this is by calling ``.count()`` first to figure out how
+ many to return, then by slicing by that size and returning
+ ALL possible search results.
Don't use this if you've got 1000s of results!
@@ -622,7 +622,12 @@ def test_len(self):
assert isinstance(len(self.get_s()), int)
def test_all(self):
- assert isinstance(self.get_s().all(), SearchResults)
+ assert isinstance(self.get_s().all(), S)
+
+ def test_everything(self):
+ ret = self.get_s().everything()
+ assert isinstance(ret, SearchResults)
+ eq_(len(ret), len(self.data))
def test_order_by(self):
res = self.get_s().filter(tag='awesome').order_by('-width')

0 comments on commit 58ccf86

Please sign in to comment.