Skip to main content

PostgreSQL-backed catalog for Plone replacing ZCatalog BTrees indexes

Project description

plone.pgcatalog

PostgreSQL-backed catalog for Plone, replacing ZCatalog BTrees indexes with SQL queries on JSONB.

Requires zodb-pgjsonb as the ZODB storage backend.

Features

  • All standard index types supported: FieldIndex, KeywordIndex, DateIndex, BooleanIndex, DateRangeIndex, UUIDIndex, ZCTextIndex, ExtendedPathIndex, GopipIndex
  • DateRecurringIndex for recurring events (Plone's start/end indexes) -- recurrence expansion at query time via rrule_plpgsql, no C extensions needed
  • Extensible via IPGIndexTranslator named utilities for custom index types
  • Dynamic index discovery from ZCatalog at startup -- addons adding indexes via catalog.xml just work
  • Transactional writes -- catalog data written atomically alongside object state during ZODB commit
  • Full-text search via PostgreSQL tsvector/tsquery -- language-aware stemming for SearchableText (30 languages), word-level matching for Title/Description/addon ZCTextIndex fields
  • Optional BM25 ranking -- when vchord_bm25 + pg_tokenizer extensions are detected, search results are automatically ranked using BM25 (IDF, term saturation, length normalization) instead of ts_rank_cd. Title matches are boosted. Falls back to tsvector ranking on vanilla PostgreSQL.
  • Zero ZODB cache pressure -- no BTree/Bucket objects stored in ZODB
  • Container-friendly -- works on standard postgres:17 Docker images; for BM25 use tensorchord/vchord-suite:pg17-latest

Requirements

  • Python 3.12+
  • PostgreSQL 15+ (tested with 17)
  • zodb-pgjsonb
  • Plone 6

Installation

pip install plone-pgcatalog

Add to your Zope configuration:

<!-- zope.conf -->
%import zodb_pgjsonb
<zodb_main>
  <pgjsonb>
    dsn dbname=mydb user=zodb password=zodb host=localhost port=5432
  </pgjsonb>
</zodb_main>

Install the plone.pgcatalog:default GenericSetup profile through Plone's Add-on installer or your policy package.

Usage

Once installed, portal_catalog is replaced with PlonePGCatalogTool. All catalog queries use the same ZCatalog API:

# Standard catalog queries -- same syntax as ZCatalog
results = catalog(portal_type="Document", review_state="published")
results = catalog(Subject={"query": ["Python", "Plone"], "operator": "or"})
results = catalog(SearchableText="my search term")
results = catalog(SearchableText="Katzen", Language="de")  # language-aware stemming
results = catalog(Title="quick fox")  # word-level match (finds "The Quick Brown Fox")
results = catalog(path={"query": "/plone/folder", "depth": 1})

# Recurring events (DateRecurringIndex)
results = catalog(start={
    "query": [DateTime("2025-03-01"), DateTime("2025-03-31")],
    "range": "min:max",
})

Migrating an Existing Site

If you have a running Plone site and want to switch from ZCatalog to plone.pgcatalog:

Prerequisites: Your site must already be running on zodb-pgjsonb. If you're migrating from FileStorage or RelStorage, use zodb-convert first.

Steps:

  1. Install plone-pgcatalog into your Python environment:

    pip install plone-pgcatalog
    
  2. Restart Zope (plone.pgcatalog is auto-discovered via z3c.autoinclude).

  3. Install the plone.pgcatalog:default GenericSetup profile -- either through the Plone Add-on control panel or programmatically:

    setup = portal.portal_setup
    setup.runAllImportStepsFromProfile("profile-plone.pgcatalog:default")
    

    This replaces portal_catalog with PlonePGCatalogTool, preserving any addon-provided index definitions.

  4. Rebuild the catalog to populate PostgreSQL with all existing content:

    catalog = portal.portal_catalog
    catalog.clearFindAndRebuild()
    

    For a site with ~1000 documents, this takes about 15 seconds.

An automated migration script is included in example/scripts/migrate_to_pgcatalog.py that performs all steps and verifies the result.

Using with plone.distribution

An example distribution package is included in example/pgcatalog-example-distribution/. It registers a "Plone Site (PG Catalog)" distribution that appears in the site creation UI and automatically applies the plone.pgcatalog:default profile.

To use plone.pgcatalog in your own distribution, add it to profiles.json:

{
  "base": [
    "plone.app.contenttypes:default",
    "plonetheme.barceloneta:default",
    "plone.pgcatalog:default"
  ]
}

Documentation

Rendered documentation: https://bluedynamics.github.io/plone-pgcatalog/

  • Architecture -- design, index registry, query translation
  • BENCHMARKS.md -- performance comparison vs RelStorage+ZCatalog
  • CHANGES.md -- changelog
  • example/ -- runnable example with multilingual content and an example distribution

Source Code and Contributions

The source code is managed in a Git repository, with its main branches hosted on GitHub. Issues can be reported there too.

We'd be happy to see many forks and pull requests to make this package even better. We welcome AI-assisted contributions, but expect every contributor to fully understand and be able to explain the code they submit. Please don't send bulk auto-generated pull requests.

Maintainers are Jens Klein and the BlueDynamics Alliance developer team. We appreciate any contribution and if a release on PyPI is needed, please just contact one of us. We also offer commercial support if any training, coaching, integration or adaptations are needed.

License

GPL-2.0

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plone_pgcatalog-1.0.0b54.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plone_pgcatalog-1.0.0b54-py3-none-any.whl (139.3 kB view details)

Uploaded Python 3

File details

Details for the file plone_pgcatalog-1.0.0b54.tar.gz.

File metadata

  • Download URL: plone_pgcatalog-1.0.0b54.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for plone_pgcatalog-1.0.0b54.tar.gz
Algorithm Hash digest
SHA256 ea5cac2e8d2ac42e58d8b3bdd8617d5c4ba54470295d5dc6ac6704bf0e47b579
MD5 ad146fe4c29dc8471d54f75cb371687b
BLAKE2b-256 9c79ffaec7678684963bcca3c1c36e946bc8c1e5498e448bf31574ce9cbdd9e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for plone_pgcatalog-1.0.0b54.tar.gz:

Publisher: release.yaml on bluedynamics/plone-pgcatalog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plone_pgcatalog-1.0.0b54-py3-none-any.whl.

File metadata

File hashes

Hashes for plone_pgcatalog-1.0.0b54-py3-none-any.whl
Algorithm Hash digest
SHA256 0b4ca82d0af373a93ea5cc1e7d9e4342669b832972eea9e187a27639a50e0bfa
MD5 b6271d9815e51274f5ec60a027593979
BLAKE2b-256 70d52303484c11b1d581ba17308744697a7646096e1ddd0ad2012a8af56d7d9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for plone_pgcatalog-1.0.0b54-py3-none-any.whl:

Publisher: release.yaml on bluedynamics/plone-pgcatalog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page