Campbell
Campbell

Reputation: 725

Adding indexes to custom catalog

I'm creating several catalogs for different types of objects, hoping to speed things up and reduce conflicts. I've been working with this document:

http://collective-docs.readthedocs.org/en/latest/searching_and_indexing/catalog.html#minimal-code-for-creating-a-new-catalog

The site builds without errors, the catalog is created, but the indexes and metadata columns don't get added to the catalog.

I've tried adding a new block to catalog.xml, and that fails with the following error:

ExpatError: catalog.xml: junk after document element: line 158, column 0

Which is the line that my new block begins - I am guessing that catalog.xml is for portal_catalog and no other.

I've found an obvious-sounding function called ZCatalog.py/addIndex()...

But my question is - what does 'best practice' look like? What I'd really like is to find a living example of a project that adds multiple catalogs and indexes on installation.

Documentation links would also be first prize.

Thanks for your time so far. and in advance, too.

Upvotes: 2

Views: 211

Answers (1)

vangheem
vangheem

Reputation: 3293

I've usually added install code to do this for me--I don't think the catalog.xml file handles additional catalogs.

cat = getToolByName(context, 'catalog_name')
cat.addIndex(name, 'FieldIndex') # or whatever index you want it to be.
# for metadata
cat.addColumn(name)

Just put something like that in an import step method.

Upvotes: 5

Related Questions