How can I exclude a subject in a Mosaic content listing tile?

Any trick how to customize the content-listing tile or add-on?
Thanks for any hint!

Perhaps, override the template plone.app.standardtiles/listing_view.pt at main · plone/plone.app.standardtiles · GitHub via z3c.jbot

I'm thinking of creating an additional criterium operation
plone.app.querystring.operation.selection.not
This is, I bet, already done by someone.

I use a boolean Field via Behavior for "News Item", if this checked then the News is a "Sticky News" and pinned on top of site in a viewlet.
I think it can be adapted for "isEmpty" or "shouldNotContain" or whatever.

You need a catalog index

<!--catalog.xml-->
  <index
    name="is_sticky"
    meta_type="BooleanIndex">
    <indexed_attr value="is_sticky" />
  </index>

You need a indexer

<!--indexer.zcml-->
<configure xmlns="http://namespaces.zope.org/zope">
  <adapter
    factory=".my_indexer.sticky_news"
    name="is_sticky" />
</configure>
# my_indexer.py
# -*- coding: utf-8 -*-
from plone.app.contenttypes.interfaces import INewsItem
from plone.indexer import indexer
from my.addon.behaviors.sticky_news import StickyNews

@indexer(INewsItem)
def sticky_news(obj):
    """Calculate and return the value for the indexer"""
    sticky = StickyNews(obj)
    if not sticky:
        return False
    return sticky.enable

You need a querystring definition

<!--registry.xml-->
<records
  interface="plone.app.querystring.interfaces.IQueryField"
  prefix="plone.app.querystring.field.is_sticky">
  <value
    key="title"
    i18n:translate="">Sticky News</value>
  <value key="description">check is the sticky news behavior available and set</value>
  <value key="enabled">True</value>
  <value key="sortable">False</value>
  <value key="operations">
    <element>plone.app.querystring.operation.boolean.isTrue</element>
    <element>plone.app.querystring.operation.boolean.isFalse</element>
  </value>
  <value key="group">Custom</value>
</records>

with all these steps, a filter in a collection is available.

That's nice. To avoid forcing the editor to mark the content, a boolean index with "not these subjects" would do. It's a hack cause it's tailored for one single use case, but hey. Obviously querying does not offer a boolean NOT. Should have known.

I have asked a similar question (here), but I did not find it.

The solution is to make a new indexer (that 'return True' when not these subject)

afaict portal_catalog nowadays support not queries. Maybe something like plone.api.content.find(not={'my:' 'query'} works?

The problem is I think not in what portal_catalog supports, but in the expressiveness of the querystring widget and the underlying key-operation-value triplets that are stored (I forgot the exact terminolgy in there).

This for example also limits/does not support grouping filter statements in logical and/or groups and other more advanced queries.

Maybe you can get away with adding a 'not' operation but the ordering of other filter items and those following the not becomes important, (should another rule after the not be additive again?) there is no reordering, etc etc.

The query argument is a logical conjunction. Logical conjunctions are commutative. That means the order of the operands does not change the result.

Unfortunatly multiple operands on the same index are allowed in a Mosaic content listing tile. The last wins.

Just for the records: An operation
plone.app.querystring.operation.selection.exclude is possible (as ZCatalog actually supports boolean NOT in queries on KeywordIndex since version 3) and makes sense to add it to

<records interface="plone.app.querystring.interfaces.IQueryField"
             prefix="plone.app.querystring.field.Subject">

but the result is the set of documents that are indexed: all documents with a 'Subject'. So all documents without Subjects are ignored. Which is not what is expected. There's more work to do.

The operation method would be

def _exclude(context, row):
    return {row.index: {'not': row.values}}