Accueil » Installation d'un ZCTextIndex ou d'un TextIndexNG2 pour un produit CMF

Installation d'un ZCTextIndex ou d'un TextIndexNG2 pour un produit CMF

Document Actions

Par davconvent le 09/03/2005 21:33

Avec Archetypes, il est très facile de préciser un index pour un champ, sauf lorsqu'il s'agit d'un ZCTextIndex ou d'un TextIndexNG2 avec des paramètres spéciaux. Ce tutoriel se propose d'expliquer comment il est possible d'installer de tels indexes à partir du script d'installation d'un produit adapté au CMF.

Catégories : CPS,CMF,Plone

Précision: ce tutoriel ne couvre pas l'installation du produit TextIndexNG2 et de ses dépendances.

Les parties intéressantes du script ('MonProduit/Extensions/Install.py'):

from StringIO import StringIO
from Products.CMFCore.utils import getToolByName
from ZPublisher.HTTPRequest import record
## ICI: .. autres imports (ex: globals, archetypes, etc)

PROJECTNAME = 'MonProduit'

# extra args pour un ZCTextIndex index à ajouter au portal_catalog
zcti_extra = record()
zcti_extra.lexicon_id = 'plone_lexicon'
zcti_extra.index_type = 'Okapi BM25 Rank'
zcti_extra.doc_attr   = None

# extra args pour un TextIndexNG2 index à ajouter au portal_catalog
ting2_extra = record()
ting2_extra.indexed_fields   = 'Title,Description,getMonArchChamp'
ting2_extra.default_encoding = 'utf-8'
ting2_extra.use_converters   = 1

# indexes à ajouter au portal_catalog
catalog_indexes = (
  
{ 'name'  : 'MonTextIndexNG2',
    
'type'  : 'TextIndexNG2',
    
'extra' : ting2_extra
  
},
  
{ 'name'  : 'MonZCTextIndex',
    
'type'  : 'ZCTextIndex',
    
'extra' : zcti_extra
    
},
                   
)

# metadatas (columns) à ajouter au portal_catalog
catalog_columns = ('SomeData', 'SomeOtherData')

def installIndexes(self, out):
    
"""ajoute les indexes et metadatas au portal catalog"""
    
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)

def install(self):
    
out = StringIO()

    
## ICI: .. autres méthodes d'installations (ex install des types et skins)

    
installIndexes(self, out)

    
print >> out, "Successfully installed %s." % PROJECTNAME
    
return out.getvalue()
Aidez l'AfPy

Rechercher
Dernières news AFPY
Les 6 dernières news
PyCon FR - 17-18 mai - Paris
07/05/2008 07:05
AFPyro d'Avril
24/04/2008 00:00