Source (Text):
from StringIO import StringIO
from Products.CMFCore.utils import getToolByName
from ZPublisher.HTTPRequest import record
[.. Other imports (globals, archetypes, etc) ..]
PROJECTNAME = 'My Project Name'
zcti_extra = record()
zcti_extra.lexicon_id = 'plone_lexicon'
zcti_extra.index_type = 'Okapi BM25 Rank'
zcti_extra.doc_attr = None
ting2_extra = record()
ting2_extra.indexed_fields = 'myField,myOtherField'
ting2_extra.default_encoding = 'utf-8'
ting2_extra.use_converters = 1
catalog_indexes = (
{ 'name' : 'SomeData',
'type' : 'TextIndex'
},
{ 'name' : 'SomeOtherData',
'type' : 'KeywordIndex'
},
{ 'name' : 'MyTextIndexNG2',
'type' : 'TextIndexNG2',
'extra' : ting2_extra
},
{ 'name' : 'MyZCTextIndex',
'type' : 'ZCTextIndex',
'extra' : zcti_extra
},
)
catalog_columns = ('SomeData', 'SomeOtherData')
def install(self):
out = StringIO()
[.. Other installation stuff (i.e. types and skins setup) ..]
ct = getToolByName(self, 'portal_catalog')
for idx in catalog_indexes:
if idx['name'] in ct.indexes():
out.write("Found the '%s' index in the catalog, nothing changed.\n" % idx['name'])
else:
ct.addIndex(**idx)
out.write("Added '%s' (%s) to the catalog.\n" % (idx['name'], idx['type']))
for entry in catalog_columns:
if entry in ct.schema():
out.write("Found '%s' in the catalog metadatas, nothing changed.\n" % entry)
else:
ct.addColumn(entry)
out.write("Added '%s' to the catalog metadatas.\n" % entry)
print >> out, "Successfully installed %s." % PROJECTNAME
return out.getvalue()
|