def __init__(self, FULLTEXT=False): """ """ self.no_refresh = True ZCatalog.__init__(self, self.getId()) self._catalog = PlominoCatalog() # TODO: use TextindexNG3 #lexicon = PLexicon('plaintext_lexicon', '', Splitter(), CaseNormalizer(), StopWordRemover()) lexicon = PLexicon('plaintext_lexicon', '', Splitter(), CaseNormalizer()) self._setObject('plaintext_lexicon', lexicon) #self.createFieldIndex('Form', 'SELECTION') #self.createFieldIndex('getPlominoReaders', 'SELECTION') self.addIndex('Form', "FieldIndex") self.addIndex('id', "FieldIndex") self.addColumn('id') self.addIndex('getPlominoReaders', "KeywordIndex") if FULLTEXT: self.createFieldIndex('SearchableText', 'RICHTEXT') self.no_refresh = False
class PlominoIndex(UniqueObject, CatalogTool): """ Plomino index """ security = ClassSecurityInfo() id = 'plomino_index' # Methods security.declarePublic('__init__') def __init__(self, FULLTEXT=False): """ """ self.no_refresh = True CatalogTool.__init__(self) self._catalog = PlominoCatalog() # TODO: use TextindexNG3 #lexicon = PLexicon('plaintext_lexicon', '', Splitter(), CaseNormalizer(), StopWordRemover()) lexicon = PLexicon('plaintext_lexicon', '', Splitter(), CaseNormalizer()) self._setObject('plaintext_lexicon', lexicon) #self.createFieldIndex('Form', 'SELECTION') #self.createFieldIndex('getPlominoReaders', 'SELECTION') self.addIndex('Form', "FieldIndex") self.addIndex('id', "FieldIndex") self.addColumn('id') self.addIndex('getPlominoReaders', "KeywordIndex") self.addIndex('path', "ExtendedPathIndex") if FULLTEXT: self.createFieldIndex('SearchableText', 'RICHTEXT') self.no_refresh = False security.declareProtected(DESIGN_PERMISSION, 'createIndex') def createIndex(self, fieldname, refresh=True): """ """ if not fieldname in self.indexes(): self._catalog.addIndex(fieldname, PlominoColumnIndex(fieldname)) if not self._catalog.schema.has_key(fieldname): self.addColumn(fieldname) if refresh: self.refresh() security.declareProtected(DESIGN_PERMISSION, 'createFieldIndex') def createFieldIndex(self, fieldname, fieldtype, refresh=True, indextype='DEFAULT', fieldmode=None): """ """ if indextype == 'DEFAULT': indextype = get_field_types()[fieldtype][1] if indextype == 'ZCTextIndex': plaintext_extra = SimpleRecord(lexicon_id='plaintext_lexicon', index_type='Okapi BM25 Rank') if not fieldname in self.indexes(): self.addIndex(fieldname, 'ZCTextIndex', plaintext_extra) if (fieldtype == 'ATTACHMENT' and self.getParentDatabase().getIndexAttachments()): if not 'PlominoFiles_' + fieldname in self.indexes(): self._catalog.addIndex( 'PlominoFiles_%s' % fieldname, PlominoFileIndex('PlominoFiles_%s' % fieldname, caller=self, extra=plaintext_extra)) else: if not fieldname in self.indexes(): if fieldmode == 'DISPLAY': display_extra = SimpleRecord( indexed_attrs='%s%s' % (DISPLAY_INDEXED_ATTR_PREFIX, fieldname)) self.addIndex(fieldname, indextype, extra=display_extra) else: self.addIndex(fieldname, indextype) if not self._catalog.schema.has_key(fieldname): self.addColumn(fieldname) if refresh: self.refresh() security.declareProtected(DESIGN_PERMISSION, 'createSelectionIndex') def createSelectionIndex(self, fieldname, refresh=True): """ """ if not fieldname in self.indexes(): self._catalog.addIndex(fieldname, PlominoViewIndex(fieldname)) if refresh: self.refresh() security.declareProtected(DESIGN_PERMISSION, 'deleteIndex') def deleteIndex(self, fieldname, refresh=True): """ """ self.delIndex(fieldname) self.delColumn(fieldname) if refresh: self.refresh() security.declareProtected(READ_PERMISSION, 'indexDocument') def indexDocument(self, doc, idxs=None, update_metadata=1): """ """ try: self.catalog_object(doc, "/".join(doc.getPhysicalPath()), idxs=idxs, update_metadata=update_metadata) except Exception, e: _logger.info('indexDocument> %s\non %s' % (repr(e), doc.id), exc_info=True) raise
class PlominoIndex(UniqueObject, ZCatalog, ActionProviderBase): """Plomino index """ security = ClassSecurityInfo() #id = 'plomino_index' manage_options = (ZCatalog.manage_options + ActionProviderBase.manage_options + ({ 'label': 'Overview', 'action': 'manage_overview' }, )) # Methods security.declarePublic('__init__') def __init__(self, FULLTEXT=False): """ """ self.no_refresh = True ZCatalog.__init__(self, self.getId()) self._catalog = PlominoCatalog() # TODO: use TextindexNG3 #lexicon = PLexicon('plaintext_lexicon', '', Splitter(), CaseNormalizer(), StopWordRemover()) lexicon = PLexicon('plaintext_lexicon', '', Splitter(), CaseNormalizer()) self._setObject('plaintext_lexicon', lexicon) #self.createFieldIndex('Form', 'SELECTION') #self.createFieldIndex('getPlominoReaders', 'SELECTION') self.addIndex('Form', "FieldIndex") self.addIndex('id', "FieldIndex") self.addColumn('id') self.addIndex('getPlominoReaders', "KeywordIndex") if FULLTEXT: self.createFieldIndex('SearchableText', 'RICHTEXT') self.no_refresh = False security.declareProtected(DESIGN_PERMISSION, 'createIndex') def createIndex(self, fieldname, refresh=True): """ """ if not fieldname in self.indexes(): self._catalog.addIndex(fieldname, PlominoColumnIndex(fieldname)) if not self._catalog.schema.has_key(fieldname): self.addColumn(fieldname) if refresh: self.refresh() security.declareProtected(DESIGN_PERMISSION, 'createFieldIndex') def createFieldIndex(self, fieldname, fieldtype, refresh=True): """ """ indextype = get_field_types()[fieldtype][1] if indextype == 'ZCTextIndex': plaintext_extra = SimpleRecord(lexicon_id='plaintext_lexicon', index_type='Okapi BM25 Rank') if not fieldname in self.indexes(): self.addIndex(fieldname, 'ZCTextIndex', plaintext_extra) if fieldtype == 'ATTACHMENT' and self.getParentDatabase( ).getIndexAttachments(): if not 'PlominoFiles_' + fieldname in self.indexes(): self._catalog.addIndex( 'PlominoFiles_' + fieldname, PlominoFileIndex('PlominoFiles_' + fieldname, caller=self, extra=plaintext_extra)) else: if not fieldname in self.indexes(): self.addIndex(fieldname, indextype) if not self._catalog.schema.has_key(fieldname): self.addColumn(fieldname) if refresh: self.refresh() security.declareProtected(DESIGN_PERMISSION, 'createSelectionIndex') def createSelectionIndex(self, fieldname, refresh=True): """ """ if not fieldname in self.indexes(): self._catalog.addIndex(fieldname, PlominoViewIndex(fieldname)) if refresh: self.refresh() security.declareProtected(DESIGN_PERMISSION, 'deleteIndex') def deleteIndex(self, fieldname, refresh=True): """ """ self.delIndex(fieldname) self.delColumn(fieldname) if refresh: self.refresh() security.declareProtected(READ_PERMISSION, 'indexDocument') def indexDocument(self, doc, idxs=None, update_metadata=1): """ """ #self.catalog_object(doc, "/".join(doc.getPhysicalPath())) try: # TODO DONE LATER (cataloging real path is better but it implies # to test all the side-effect and provide a migration script) #self.catalog_object(doc) db = doc.getParentDatabase() self.catalog_object(doc, "/".join(db.getPhysicalPath()) + "/" + doc.id, idxs=idxs, update_metadata=update_metadata) except Exception, e: self.portal_skins.plone_scripts.plone_log('%s\non %s' % ( ` e `, doc.id)) raise