def installCatalog(self): '''Create the catalog at the root of Zope if id does not exist.''' if 'catalog' not in self.app.objectIds(): # Create the catalog from Products.ZCatalog.ZCatalog import manage_addZCatalog manage_addZCatalog(self.app, 'catalog', '') self.logger.info('Appy catalog created.') # Create lexicons for ZCTextIndexes catalog = self.app.catalog lexicons = catalog.objectIds() from Products.ZCTextIndex.ZCTextIndex import manage_addLexicon if 'xhtml_lexicon' not in lexicons: lex = appy.Object(group='XHTML indexer', name='XHTML indexer') manage_addLexicon(catalog, 'xhtml_lexicon', elements=[lex]) if 'text_lexicon' not in lexicons: lex = appy.Object(group='Text indexer', name='Text indexer') manage_addLexicon(catalog, 'text_lexicon', elements=[lex]) if 'list_lexicon' not in lexicons: lex = appy.Object(group='List indexer', name='List indexer') manage_addLexicon(catalog, 'list_lexicon', elements=[lex]) # Delete the deprecated one if it exists if 'lexicon' in lexicons: catalog.manage_delObjects(['lexicon']) # Create or update Appy-wide indexes and field-related indexes indexInfo = defaultIndexes.copy() tool = self.app.config for className in self.config.attributes.iterkeys(): wrapperClass = tool.getAppyClass(className, wrapper=True) indexInfo.update(wrapperClass.getIndexes(includeDefaults=False)) updateIndexes(self, indexInfo)
def getIndexes(klass, includeDefaults=True): '''Returns a dict whose keys are the names of the indexes that are applicable to instances of this class, and whose values are the (Zope) types of those indexes.''' # Start with the standard indexes applicable for any Appy class. if includeDefaults: res = defaultIndexes.copy() else: res = {} # Add the indexed fields found on this class for field in klass.__fields__: if not field.indexed or (field.name == 'title'): continue n = field.name indexName = 'get%s%s' % (n[0].upper(), n[1:]) res[indexName] = field.getIndexType() return res
def getIndexes(klass, includeDefaults=True): """Returns a dict whose keys are the names of the indexes that are applicable to instances of this class, and whose values are the (Zope) types of those indexes.""" # Start with the standard indexes applicable for any Appy class. if includeDefaults: res = defaultIndexes.copy() else: res = {} # Add the indexed fields found on this class for field in klass.__fields__: if not field.indexed or (field.name == "title"): continue n = field.name indexName = "get%s%s" % (n[0].upper(), n[1:]) res[indexName] = field.getIndexType() return res
def installCatalog(self): '''Create the catalog at the root of Zope if id does not exist.''' if 'catalog' not in self.app.objectIds(): # Create the catalog from Products.ZCatalog.ZCatalog import manage_addZCatalog manage_addZCatalog(self.app, 'catalog', '') self.logger.info('Appy catalog created.') # Create lexicons for ZCTextIndexes catalog = self.app.catalog lexicons = catalog.objectIds() from Products.ZCTextIndex.ZCTextIndex import manage_addLexicon if 'xhtml_lexicon' not in lexicons: lex = appy.Object(group='XHTML indexer', name='XHTML indexer') manage_addLexicon(catalog, 'xhtml_lexicon', elements=[lex]) if 'text_lexicon' not in lexicons: lex = appy.Object(group='Text indexer', name='Text indexer') manage_addLexicon(catalog, 'text_lexicon', elements=[lex]) if 'list_lexicon' not in lexicons: lex = appy.Object(group='List indexer', name='List indexer') manage_addLexicon(catalog, 'list_lexicon', elements=[lex]) # Delete the deprecated one if it exists if 'lexicon' in lexicons: catalog.manage_delObjects(['lexicon']) # Create or update Appy-wide indexes and field-related indexes indexInfo = defaultIndexes.copy() tool = self.app.config for className in self.config.attributes.iterkeys(): wrapperClass = tool.getAppyClass(className, wrapper=True) indexInfo.update(wrapperClass.getIndexes(includeDefaults=False)) updateIndexes(self, indexInfo) # Re-index index "SearchableText", wrongly defined for Appy < 0.8.3. stIndex = catalog.Indexes['SearchableText'] if stIndex.indexSize() == 0: self.logger.info('reindexing SearchableText...') catalog.reindexIndex('SearchableText', self.app.REQUEST) self.logger.info('done.')