pluggablecatalog

Warning
This product has not had a release in over 1 year and may no longer be maintained.
by Daniel Nouri last modified Feb 16, 2011 02:08 AM

pluggablecatalog is a replacement (or rather: a wrapper) for Plone's portal catalog. It adds the ability to plug in search restrictions without the need to subclass or monkey- patch the catalog.

Project Description

This is the tool's docstring showing one example usage. Using the pluggablecatalog is as simple as defining your own IQueryDefaults utility. More plugin points are planned:

Wraps CMFPlone's CatalogTool to add default parameters
collected from IQueryDefaults utilities.

Install the catalog:

  >>> from StringIO import StringIO
  >>> from Products.pluggablecatalog.Extensions.install \
  ...     import _replaceCatalog
  >>> self.loginAsPortalOwner()
  >>> _replaceCatalog(self.portal, StringIO())
  >>> self.login()

  >>> from Products.pluggablecatalog.tool import CatalogTool
  >>> catalog = self.portal.portal_catalog
  >>> isinstance(catalog, CatalogTool)
  True

We create two documents and make sure they're indexed:

  >>> before = len(catalog())
  >>> self.folder.invokeFactory('Document', 'doc1')
  'doc1'
  >>> self.folder.invokeFactory('Document', 'doc2')
  'doc2'
  >>> doc1, doc2 = self.folder.doc1, self.folder.doc2
  >>> doc1.setTitle('First Document')
  >>> doc2.setTitle('Second Document')
  >>> doc1.reindexObject(); doc2.reindexObject()
  >>> len(catalog()) - before
  2

Let's now add a rather stupid IQueryDefaults utility that
restricts searches by default to objects with the Title 'First
Document':

  >>> from zope import component
  >>> from zope import interface
  >>> from Products.pluggablecatalog.interfaces import IQueryDefaults
  >>> def myDefaults(context, request):
  ...     return {'Title': 'First Document'}
  >>> interface.directlyProvides(myDefaults, IQueryDefaults)
  >>> component.provideUtility(myDefaults)

With this utility in place, we should only retrieve doc1 now,
unless we explicitly provide a 'Title' query parameter:

  >>> len(catalog())
  1
  >>> catalog()[0].getObject().aq_base is doc1.aq_base
  True

  >>> len(catalog(Title='Second Document'))
  1
  >>> (catalog(Title='Second Document')[0].getObject().aq_base is
  ...  doc2.aq_base)
  True

Current Release
pluggablecatalog 1.0

Released Jul 24, 2008 — tested with Plone 2.5, Plone 3

Release of the newly eggified version of Products.pluggablecatalog.
More about this release…

Download file Get pluggablecatalog for all platforms
Product Source Distribution
If you are using Plone 3.2 or higher, you probably want to install this product with buildout. See our tutorial on installing add-on products with buildout for more information.

All Releases

Version Released Description Compatibility Status
1.0 Jul 24, 2008 Release of the newly eggified version of Products.pluggablecatalog. More about this release…
Plone 2.5
Plone 3
final

Comments (0)