Configuring Catalogs with GenericSetup

by Plone Documentation Team last modified Sep 22, 2009 09:29 PM
Contributors: Mikko Ohtamma, Martin Aspeli, Kamon Ayeva, Israel Saeta Pérez
Adding, removing and changing indexes and metadata.

The Catalog Tool can be configured through the ZMI or programatically in Python but current best practice in the CMF world is to use GenericSetup to configure it using the declarative catalog.xml file. The GenericSetup profile for Plone, for example, uses the CMFPlone/profiles/default/catalog.xml XML data file to configure the Catalog Tool when a Plone site is created. It is fairly readable so taking a quick look through it can be very informative.

When using a GenericSetup extension profile to customize the Catalog Tool in your portal, you only need to include XML for the pieces of the catalog you are changing. To add an index for the Archetypes location field, as in the example above, a policy package could include the following profiles/default/catalog.xml:

    <?xml version="1.0"?>
    <object name="portal_catalog" meta_type="Plone Catalog Tool">
     <index name="location" meta_type="FieldIndex">
      <indexed_attr value="location"/>
     </index>
    </object>

The GenericSetup import handler for the Catalog Tool also supports removing indexes from the catalog if present using the "remove" attribute of the <index> element. To remove the "start" and "end" indexes used for events, for example, a policy package could include the following profiles/default/catalog.xml:

    <?xml version="1.0"?>
    <object name="portal_catalog" meta_type="Plone Catalog Tool">
     <index name="start" remove="True" />
     <index name="end" remove="True" />
    </object>

Care must be taken when setting up indexes with GenericSetup - if the import step for a catalog.xml is run a second time (for example when you reinstall the product), the indexes specified will be destroyed, losing all currently indexed entries, and then re-created fresh (and empty!). If you want to workaround this behaviour, you can either update the catalog afterwards or add the indexes yourself in Python code using a custom import handler.