Stuff the catalog

Adding extra information to the portal catalog can be an easy way to get information from across your site. Plone let’s you easily create extra indexes using a generic setup profile. If you have an existing profile you can add a file catalog.xml with the following contents:

<?xml version=”1.0″?>
<object name=”portal_catalog” meta_type=”Plone Catalog Tool”>
<column value=”FirstLetter”/>
<index name=”FirstLetter” meta_type=”FieldIndex”>
<indexed_attr value=”FirstLetter”/>
This will create both a field index named FirstLetter and a corresponding meta data column (this will be available on the result objects when querying the catalog). There are many kind of indexes you can create this way. You can see how to use some of them in Plone’s own catalog.xml file.

Now we need to make sure we that our FirstLetter index will be filled. We can do this by creating a simple Python function. Let’s create a new file for this in our project named with this content:

from Products.CMFPlone.CatalogTool import registerIndexableAttribute

def first_letter(obj, portal, vars, **kwargs):
     # Make sure we have a title with something in it
    if obj.Title():
        # Return the first letter
        return obj.Title()[0].lower()

registerIndexableAttribute('FirstLetter', first_letter)

This will register an extra handler for Plone’s indexing system. To make sure it is registered we need to import the catalog module from the of the project/product. Just add a line like this to your project (replace exampleproject with your project’s name):

import exampleproject.catalog

This should make the FirstName index available when the project is installed. Now you query your catalog against this with something like:



1 comment so far

  1. yboussard on

    Be carreful !
    If you relaunch generic setup the index is clear !!

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: