Skip to content

Commit

Permalink
Merge 00d2a0a into c4e4cd5
Browse files Browse the repository at this point in the history
  • Loading branch information
d-maurer committed Jul 29, 2020
2 parents c4e4cd5 + 00d2a0a commit c188e04
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Expand Up @@ -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 <https://github.com/zopefoundation/Products.ZCatalog/issues/102>`_).

- Fix case where index value is changed to None after previously being indexed.
(`#100 <https://github.com/zopefoundation/Products.ZCatalog/issues/100>`_)

Expand Down
8 changes: 8 additions & 0 deletions src/Products/ZCatalog/ZCatalog.py
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/Products/ZCatalog/dtml/catalogView.dtml
Expand Up @@ -3,8 +3,8 @@

<main class="container-fluid">

<dtml-let filterpath="REQUEST.get('filterpath', '/')"
results="searchResults(path=filterpath)">
<dtml-let filterpath="REQUEST.get('filterpath', '')"
results="searchResults(path=filterpath) if filterpath else searchAll()">
<dtml-if results>

<h1 class="form-label section-bar">Path filter</h1>
Expand Down
6 changes: 6 additions & 0 deletions src/Products/ZCatalog/interfaces.py
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions src/Products/ZCatalog/tests/test_zcatalog.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):

Expand Down

0 comments on commit c188e04

Please sign in to comment.