[zopeorg-checkins] CVS: Products/ZopeOrg-NV/Extensions - setupZopeOrg.py:1.63

Sidnei da Silva sidnei at x3ng.com.br
Tue Jan 28 21:11:25 EST 2003


Update of /cvs-zopeorg/Products/ZopeOrg-NV/Extensions
In directory cvs.zope.org:/tmp/cvs-serv19765/Extensions

Modified Files:
	setupZopeOrg.py 
Log Message:
Use ZCTextIndex Yay! Reindex after replacing index. Use DCWorkflow -based workflows. Migrate ZSP (Still need to register it on Install)

=== Products/ZopeOrg-NV/Extensions/setupZopeOrg.py 1.62 => 1.63 ===
 from Products.ZopeOrg import zopeorg_globals
 from Products.CMFCore.DirectoryView import addDirectoryViews
 from Products.CMFCore.utils import getToolByName
-from Products.ZopeOrg.NewsItemWorkflow import NewsItemWorkflowDefinition
-from Products.ZopeOrg.ZopeOrgWorkflow import ZopeOrgWorkflowDefinition
 from Products.ZopeOrg.ZopeOrgTypes import ftis
 from Products.CMFCore.PortalFolder import manage_addPortalFolder
 from Products.CMFCore.TypesTool import FactoryTypeInformation
@@ -20,6 +18,7 @@
 from Products.PluginIndexes.DateIndex.DateIndex import DateIndex
 from Products.PluginIndexes.DateRangeIndex.DateRangeIndex import DateRangeIndex
 
+from Products.ZCTextIndex import ZCTextIndex
 from Products.CMFDateIndexes.RSCatalogTool import RSCatalogTool
 from Products.BTreeFolder2.CMFBTreeFolder import manage_addCMFBTreeFolder
 
@@ -66,6 +65,7 @@
               )
 
 SKINS = ( 'nzo',
+          'zopeorg_products'
         )
 
 ADD_INDEXES = ()
@@ -77,8 +77,10 @@
                   , ( 'modified', DateIndex )
                   )
 
-WORKFLOWS = ( ('News Item', NewsItemWorkflowDefinition) 
-            , ('default', ZopeOrgWorkflowDefinition)
+ZCTEXTINDEXES = ( 'Description', 'SearchableText', 'Title' )
+
+WORKFLOWS = (('default', 'zopeorg_default_workflow',
+              'Default Zope.org Workflow'), 
             )
 
 EXT_METHODS = ( { 'id' : 'ZO_setupMembership'
@@ -207,6 +209,7 @@
     catalogAddIndexes(portal, ADD_INDEXES, 'portal_catalog')
     catalogReplaceIndexes(portal, REPLACE_INDEXES, 'portal_catalog')
     catalogAddColumns(portal, ADD_COLUMNS, 'portal_catalog')
+    catalogAddZCTextIndexes(portal, ZCTEXTINDEXES, 'portal_catalog')
         
     # Setting up roles and permissions
     log.append('\n * Setting up roles and permissions')
@@ -278,7 +281,7 @@
     # Run the CMFCalendar install script
     log.append('\n * Executing CMFCalendar install script')
     if 'portal_calendar' in portal.objectIds():
-        portal.manage_delObjects(ids = ['portal_catalog'])
+        portal.manage_delObjects(ids = ['portal_calendar'])
     log_str = portal.installCMFCalendar()
     log_list = string.split(log_str, '\n')
     for i in range(len(log_list)):
@@ -405,16 +408,16 @@
 def registerWorkflow( portal_obj, wf_tuple ):
     """ Insert new zope.org workflows into the workflow tool """
     wf_portaltype = wf_tuple[0]
-    wf_class = wf_tuple[1]
-
+    wf_id = wf_tuple[1]
+    wf_title = wf_tuple[2]
+    
     wf_tool = getToolByName(portal_obj, 'portal_workflow')
-    wf_id = wf_class.id
-    wf_obj = apply(wf_class, (wf_id,))
 
     if wf_id in wf_tool.objectIds():
         wf_tool._delObject(wf_id)
 
-    wf_tool._setObject(wf_id, wf_obj)
+    wf_tool.manage_addWorkflow(id=wf_id,
+                               workflow_type='%s (%s)' % (wf_id, wf_title))
 
     if wf_portaltype == 'default':
         wf_tool.setDefaultChain(wf_id)
@@ -479,8 +482,9 @@
         index_class = index_tuple[1]
  
         try:
-            index_obj = apply( index_class, ( index_name, ) )
-            cat_core.addIndex( index_name, index_obj )
+            index_obj = apply(index_class, (index_name,))
+            cat_core.addIndex(index_name, index_obj)
+            p_cat.reindexIndex(index_name, None)
 
             added.append(index_name)
         except:
@@ -492,6 +496,58 @@
     log.append('   - Retained catalog indexes in %s: %s' %
                             (which_cat, string.join(retained, ', ')))
 
+class Record:
+    pass
+
+def catalogAddZCTextIndexes(portal_obj, index_list, which_cat):
+    """ Add ZCTextIndexes to the portal catalog """
+    p_cat = getattr(portal_obj, which_cat)
+    cat_core = p_cat._catalog
+    replaced = []
+    added = []
+ 
+    existing_indexes = cat_core.indexes
+    elements = []
+
+    el1 = Record()
+    el1.group = "Case Normalizer"
+    el1.name = "Case Normalizer"
+    elements.append(el1)
+
+    el2 = Record()
+    el2.group = "Stop Words"
+    el2.name = " Don't remove stop words"
+    elements.append(el2)
+
+    el3 = Record()
+    el3.group = "Word Splitter"
+    el3.name = "HTML aware splitter"
+    elements.append(el3)
+
+    ZCTextIndex.manage_addLexicon(p_cat, 'lexicon', 'Lexicon', elements)
+    
+    for index_name in index_list:
+        if (existing_indexes.has_key(index_name)):
+            cat_core.delIndex(index_name)
+            replaced.append(index_name)
+        else:
+            added.append(index_name)
+
+        extra = Record()
+        extra.doc_attr = index_name
+        extra.index_type = "Okapi BM25 Rank"
+        extra.lexicon_id = "lexicon"
+
+        p_cat.addIndex(index_name, 'ZCTextIndex', extra)
+        p_cat.reindexIndex(index_name, None)
+            
+    log.append('   - Added new catalog indexes to %s: %s' %
+                            (which_cat, string.join(added, ', ')))
+ 
+    log.append('   - Replaced catalog indexes in %s: %s' %
+                            (which_cat, string.join(replaced, ', ')))
+
+
 
 def catalogReplaceIndexes(portal_obj, index_list, which_cat):
     """ Replace indexes in the portal catalog """
@@ -512,6 +568,7 @@
                 cat_core.delIndex(index_name)
             index_obj = apply( index_class, ( index_name, ) )
             cat_core.addIndex( index_name, index_obj )
+            p_cat.reindexIndex(index_name, None)
             replaced.append(index_name)
  
     log.append('   - Replaced %s indexes' %
@@ -554,6 +611,7 @@
         index_obj = DateRangeIndex('effectiveRange')
         index_obj._edit(since_field='effective', until_field='expires')
         cat_core.addIndex('effectiveRange', index_obj)
+        p_cat.reindexIndex('effectiveRange', None)
 
         log.append('   - Added effectiveRange DateRangeIndex index')
 
@@ -752,7 +810,9 @@
      """
      tt = getToolByName(portal, 'portal_types')
      typesList = tt.listTypeInfo()
-     pdTypes = ['Document', 'Favorite', 'Link', 'News Item', 'File', 'Tip', 'HowTo', 'Software Package', 'Software Release', 'Software Release File']
+     pdTypes = ['Document', 'Favorite', 'Link', 'News Item',
+                'File', 'Tip', 'HowTo', 'Software Package',
+                'Software Release', 'Software Release File']
      for i in typesList:
         new_actions = []
         for dict in i._actions:





More information about the zopeorg-checkins mailing list