diff --git a/CHANGES.rst b/CHANGES.rst index a114bded..0437fe3d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,13 @@ Changelog 5.2 (unreleased) ---------------- +- Add new method ``searchAll`` to perform a search for all documents. + +- Document ``getAllBrains`` and ``searchAll`` in the interface. + +- Update `catalogView.dtml` to changed behavior of empty searches + (`#102 `_). + - Fix case where index value is changed to None after previously being indexed. (`#100 `_) diff --git a/src/Products/ZCatalog/ZCatalog.py b/src/Products/ZCatalog/ZCatalog.py index e8acc4e5..06b83959 100644 --- a/src/Products/ZCatalog/ZCatalog.py +++ b/src/Products/ZCatalog/ZCatalog.py @@ -44,6 +44,7 @@ from zExceptions import BadRequest from ZODB.POSException import ConflictError from zope.interface import implementer +from ZTUtils.Lazy import LazyMap from Products.ZCatalog.Catalog import Catalog, CatalogError from Products.ZCatalog.interfaces import IZCatalog @@ -566,6 +567,13 @@ def getAllBrains(self): for rid in self._catalog.data: yield self._catalog[rid] + @security.protected(search_zcatalog) + def searchAll(self): + # the result of a search for all documents + return LazyMap(self._catalog.__getitem__, + self._catalog.data.keys(), + len(self)) + @security.protected(search_zcatalog) def schema(self): return self._catalog.schema.keys() diff --git a/src/Products/ZCatalog/dtml/catalogView.dtml b/src/Products/ZCatalog/dtml/catalogView.dtml index c4d8ccec..45c38b36 100644 --- a/src/Products/ZCatalog/dtml/catalogView.dtml +++ b/src/Products/ZCatalog/dtml/catalogView.dtml @@ -3,8 +3,8 @@
- +

Path filter

diff --git a/src/Products/ZCatalog/interfaces.py b/src/Products/ZCatalog/interfaces.py index c4f72efb..d10022ab 100644 --- a/src/Products/ZCatalog/interfaces.py +++ b/src/Products/ZCatalog/interfaces.py @@ -222,6 +222,12 @@ def search(query, sort_index=None, reverse=0, limit=None, merge=1): queries (even across catalogs) and merge and sort the combined results. """ + def searchAll(): + """the result of a search for all documents as a sequence.""" + + def getAllBrains(): + """the result of a search for all documents as an iterator.""" + def refreshCatalog(clear=0, pghandler=None): """Reindex every object we can find, removing the unreachable ones from the index. diff --git a/src/Products/ZCatalog/tests/test_zcatalog.py b/src/Products/ZCatalog/tests/test_zcatalog.py index 04a50672..dee5678b 100644 --- a/src/Products/ZCatalog/tests/test_zcatalog.py +++ b/src/Products/ZCatalog/tests/test_zcatalog.py @@ -19,6 +19,7 @@ from Acquisition import Implicit import ExtensionClass from OFS.Folder import Folder as OFS_Folder +from Testing.makerequest import makerequest class Folder(OFS_Folder): @@ -275,6 +276,12 @@ def testGetAllBrains(self): self.assertTrue(hasattr(brain, 'title')) self.assertEqual(len(brains), len(self._catalog)) + def testSearchAll(self): + all = self._catalog.searchAll() + for b in all: + self.assertTrue(hasattr(b, 'title')) + self.assertEqual(len(all), len(self._catalog)) + # schema # indexes # index_objects @@ -307,6 +314,16 @@ def testSearchNot(self): # manage_setProgress # _getProgressThreshold + def test_catalogView(self): + catalog = makerequest(self._catalog) + # hack `getPhysicalPath` to avoid problem with the catalog plan + catalog.getPhysicalPath = None + # provide `ZopeVersion` + catalog.ZopeVersion = lambda *arg, **kw: 4 + vr = catalog.manage_catalogView() + self.assertTrue("There are no objects in the Catalog." not in vr, + "catalogView wrongly reports `no objects`") + class TestAddDelColumnIndex(ZCatalogBase, unittest.TestCase):