Using the catalog to find all items in a site

I'm puzzled why this doesn't seem to find every item in a site:

$ bin/client_reserved debug
>>> site=app.MySite
>>> len(site.portal_catalog())
602

when, if I look at the portal_catalog's id index, there are 2900 items.

...what am I missing?

try setSite(site)

and plone.api.portal.get() to check if the site is set.

You are probably not authenticated:

Probably the fastest way to get your answer is something like:

len(site.portal_catalog._catalog.data)

Or you can use unrestrictedSearchResults or the method getAllBrains :slight_smile:

Disclaimer: just telling by memory. Sorry I am too lazy and busy to test it now :slight_smile:

1 Like

There are default filters by role and effective date range. Do portal_catalog.unrestrictedSearchResults() to get all items.

1 Like

or run your code in the context of a admin user by creating a newSecurityManager()

1 Like

Or use plone.api.env.adopt_roles

I think it is also Ok to do:

brains = app.name_of_plone_site.portal_catalog()

Wrong.

Do you mean that it does not work, or that it does not find all the items?

>>> brains = app.skipshistorie.portal_catalog()
>>> len(brains)
71847

You still need to use unrestrictedSearchResult() or elevated rights using newSecurityManager() or adopt_roles() for getting all results without any portal catalog filtering.

Thank you all! The solution was indeed to call getAllBrains()

It was in the context of trying to delete old broken comments (Products.CMFDefault.DiscussionItem.DiscussionItemContainer) Editing items with very old-style DiscussionItem breaks · Issue #2877 · plone/Products.CMFPlone · GitHub