Search for every content type but NOT file

In Plone 5, it is possible to search the catalog for

portal_type = "Folder" and
portal_type = ("Folder", "Page")

But what is the best approach for finding
portal_type != "File"

Searh by review state and add a search form images
Search for everything and remove files, somehow

(Yes, I could search for portal_type = ("Every", "Content", "Type")
but then I would need to edit the code if I add another content type

NOT queries are a feature of ZCatalog 3.0 and higher. See the release notes of the 3.0 version


You could do two queries (one for all types, then one for just File) and then Python sets to find the difference.

If your first query (for all types) iterates over portal_types you won't have to edit code if you add more content types. :slight_smile:

I would do like this:

from plone import api
types_tool = api.portal.get_tool('portal_types')
types_to_find = (t for t in types_tool if t != 'File')
brains = api.content.find(portal_type=types_to_find)

Please... just go with the @zopyx answer... it's the right ones .

Not queries are documented in the CHANGES section of ZCatalog.

Yes, that is defently the right approach, although understanding the syntax is a bit difficult (I tried a lot):

From the docs, it looked like it should be something like

all_but_file_brains = catalog.searchResults(portal_type = { "query" : "not": "File" })

Read the example carefully instead of guessing some syntax. The example in the release notes is clear and obvious:

{‘portal_type’: {‘query’: [‘Type1’, 'Type2’], ‘not’: ‘Type2’}}