How to add a ZCTextIndex to the catalog
You need to add another couple of fields to the XML to define a lexicon and a sorting algorythmn as well as making the index:type = ZCTextIndex. The way that works is to remove the catalog tagged properties and then in the protected footer code area of catalog.xml, manually add the following:
<index name="getPostcode" meta_type="ZCTextIndex"> <indexed_attr value="getPostcode"/> <extra name="index_type" value="Okapi BM25 Rank"/> <extra name="lexicon_id" value="plone_lexicon"/> </index> <column value="getPostcode"/>
The way that doesn't work, possibly because we don't have the fixed version of AGX, is to add 2x index:extras tagged values of index_type=Okapi BM25 Rank and lexicon_id=plone_lexicon
This could be because I was/am using archgenxml 2.2 instead of the latest version (2.6 as of writing), because my Mac can't compile to 2.6 version.
Adding the new index via python
The problem with adding a new index via catalog.xml is that all the indexes are cleared when you reinstall the product, so you then have to reindex the site manually via the ZMI, or reindex the site post-install via python.
The alternative is to add the indexes via setuphandlers.py as explained here:
This explains exactly what to do, apart from in the case of ZCTextIndex, which is required to add a custom field to searchableText. This is just a little more complex, but can be made to work as outlined here:
To adapt it for our case, to setuphandlers.py add the following class.
class Empty: pass
Then changed the "wanted" tuple to reflect the fact that you require ZCTextIndexes.
wanted = (('getThing1', 'ZCTextIndex'), ('getThing2', 'ZCTextIndex'), ('getThing3', 'FieldIndex'), )
Then change the catalog.addIndex call to the following.
if name not in indexes: if meta_type == 'ZCTextIndex': item_extras = Empty() item_extras.doc_attr = name item_extras.index_type = 'Okapi BM25 Rank' item_extras.lexicon_id = 'plone_lexicon' catalog.addIndex(name, meta_type, item_extras) else: catalog.addIndex(name, meta_type)
Now when you reinstall, your indexes should be ZCTextIndexes. Don't forget to delete the FieldIndexes if you added your fields to the catalog as this type.
Add an index to SearchableText
Plone has a special index called SearchableText, which is what it uses for its main search mechanism. If you want your newly indexed field to be searchable via the standard search, or even via a customised search, you have to add
to the field definition. This is true both of normal field and of an _ExtensionXXXField from Schema Extender. Make sure you add it to the field and not to the widget definition within the field.