ploneplone-4.xarchetypes

Refresh non-index metadata in a Plone ZCatalog


Zope catalogs contain catalog objects with index attributes (for use as query arguments) and metadata attributes (available when accessing the search result). For index attributes, there is the possibility of reindexing for cases when the calculation logic of the index has changed.

I noticed that my getThumbnailPath metadata field was incorrect for one of my Archetypes-based content types. Of course, the metadata field contents don't change automatically when the method has changed; thus, I'd like to fix this in an upgrade step.

However, there seems to be no documented way to do this for metadata fields; the catalog reindexing documentation doesn't say much about this.

What would be the state-of-the-art way to do this?

Update: For now, I chose the 2nd possibility, but it took ~ 100 seconds for the 1069 objects of that type, and it could easily take hours with all other objects affected as well; it would be nice to have a more selective way.


Solution

  • The catalog metadata is updated whenever the object is indexed. I think the fastest way to update it is to reindex each object specifying a single index to update:

    portal_catalog.catalog_object(obj, idxs=['getId'])
    

    The time required will depend on how many objects and how many fields are included in the metadata.

    (In other cases where you want to index without taking the time to update the catalog metadata, pass update_metadata=False to this same method.)