[Zope-CVS] CVS: Products/ZCTextIndex - Lexicon.py:1.1.2.8 ZCTextIndex.py:1.1.2.17 __init__.py:1.1.2.4

Casey Duncan casey@zope.com
Wed, 8 May 2002 18:17:27 -0400


Update of /cvs-repository/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv2006

Modified Files:
      Tag: TextIndexDS9-branch
	Lexicon.py ZCTextIndex.py __init__.py 
Log Message:
Began integration in Zope
 * Changed ZCTextIndex to conform to expected PlugInIndex signature
 * Added preliminary management pages
 * Updated tests


=== Products/ZCTextIndex/Lexicon.py 1.1.2.7 => 1.1.2.8 ===
 from BTrees.IOBTree import IOBTree
 from BTrees.OIBTree import OIBTree
+from Products.ZCTextIndex.ILexicon import ILexicon
 
 class Lexicon:
+    
+    __implements__ = ILexicon
 
     def __init__(self, *pipeline):
         self.__wids = OIBTree()


=== Products/ZCTextIndex/ZCTextIndex.py 1.1.2.16 => 1.1.2.17 ===
 import ZODB
 from Persistence import Persistent
+import Acquisition
+from OFS.SimpleItem import SimpleItem
 
 from Products.PluginIndexes.common.PluggableIndex \
      import PluggableIndexInterface
 
 from Products.ZCTextIndex.Index import Index
 from Products.ZCTextIndex.Lexicon import Lexicon
+from Products.ZCTextIndex.ILexicon import ILexicon
 from Products.ZCTextIndex.NBest import NBest
 from Products.ZCTextIndex.QueryParser import QueryParser
 from Products.ZCTextIndex.StopDict import get_stopdict
+from Globals import DTMLFile
+from Interface import verify_class_implementation
 
-class ZCTextIndex(Persistent):
+class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
     __implements__ = PluggableIndexInterface
-
-    def __init__(self, doc_attr="text"):
-        self._fieldname = doc_attr
-        self.lexicon = Lexicon(Splitter(), CaseNormalizer(), StopWordRemover())
+    
+    meta_type = 'RelevanceIndex'
+    
+    manage_options= (
+        {'label': 'Settings', 'action': 'manage_main'},
+    )
+
+    def __init__(self, extra, caller):
+        self._fieldname = extra.doc_attr
+        lexicon = getattr(caller, extra.lexicon_id, None)
+        
+        if lexicon is None:
+            raise LookupError, 'Lexicon "%s" not found' % extra.lexicon_id
+            
+        verify_class_implementation(ILexicon, lexicon.__class__)
+            
+        self.lexicon = lexicon
         self.index = Index(self.lexicon)
         self.parser = QueryParser()
 
@@ -62,6 +80,10 @@
             return x()
         else:
             return x
+            
+    ## User Interface Methods ##
+    
+    manage_main = DTMLFile('dtml/manageZCTextIndex', globals())
 
 # Trivial pipeline elements
 
@@ -89,3 +111,12 @@
     def process(self, lst):
         has_key = self.dict.has_key
         return [w for w in lst if not has_key(w)]
+        
+def manage_addZCTextIndex(self, id, extra=None, REQUEST=None, 
+                          RESPONSE=None):
+    """Add a text index"""
+    return self.manage_addIndex(id, 'ZCTextIndex', extra, 
+                                REQUEST, RESPONSE, REQUEST.URL3)
+                                
+manage_addSCTextIndexForm = DTMLFile('dtml/addZCTextIndex', globals())
+


=== Products/ZCTextIndex/__init__.py 1.1.2.3 => 1.1.2.4 ===
 Experimental plugin text index for ZCatalog.
 """
+
+import ZCTextIndex
+
+def initialize(context):
+    
+    context.registerClass(
+        ZCTextIndex.ZCTextIndex,
+        permission='Add Pluggable Index',
+        constructors=(ZCTextIndex.manage_addZCTextIndexForm,
+                      ZCTextIndex.manage_addZCText),
+        visibility=None
+    )