Last modified: May 05, 2025 By Alexander Williams

Plone Catalog & Indexing for Efficient Queries

Plone's catalog and indexing system is powerful. It helps you query content fast. This guide explains how to use it effectively.

Understanding Plone's Catalog

The catalog stores metadata about content. It enables quick searches without loading full objects. This boosts performance.

When content changes, the catalog updates automatically. You can query it using Python or through the web interface.

Key Index Types in Plone

Plone supports several index types. Each serves different query needs.

FieldIndex works for exact value matches. KeywordIndex handles multiple values. DateIndex is for date ranges.

TextIndex enables full-text search. PathIndex helps with location-based queries.

Basic Catalog Queries

Use portal_catalog to perform queries. Here's a simple example:


from Products.CMFPlone.utils import getToolByName
catalog = getToolByName(context, 'portal_catalog')
results = catalog(portal_type='Document')

This returns all documents in the site. The context is typically your Plone site root.

Advanced Query Techniques

Combine multiple criteria for precise results. Use indexes effectively.


results = catalog(
    portal_type='News Item',
    effective={'query': DateTime(), 'range': 'max'},
    review_state='published'
)

This gets published news items with effective dates in the past.

Creating Custom Indexes

Add custom indexes via GenericSetup. First, create a catalog.xml file.




  
    
  


Then install it with an import step. Learn more about custom content models to extend your content types.

Optimizing Query Performance

Follow these tips for better performance:

Limit result sets with batch_size. Use specific indexes. Avoid loading full objects when possible.

For complex sites, consider Plone's architecture to understand how components interact.

Common Pitfalls and Solutions

Avoid querying without indexes. This forces full catalog scans. Always check your query plans.

Remember to reindex after schema changes. Use reindexIndex() for single indexes or reindexObject() for full objects.

Real-World Example

Here's a practical example for a news archive:


def get_recent_news(self, limit=5):
    catalog = getToolByName(self, 'portal_catalog')
    return catalog(
        portal_type='News Item',
        sort_on='effective',
        sort_order='descending',
        sort_limit=limit
    )

This gets the 5 most recent news items by publication date.

Conclusion

Plone's catalog system is flexible and powerful. Proper use improves performance dramatically.

Combine it with view components for complete solutions. Always test queries with real data volumes.

Start with simple queries. Gradually add complexity as needed. Your Plone site will benefit from optimized searches.