[Zope-CVS] CVS: Products/ZCTextIndex - ZCTextIndex.py:

Barry Warsaw barry@wooz.org
Fri, 10 May 2002 18:35:27 -0400

Update of /cvs-repository/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv14962/lib/python/Products/ZCTextIndex

Modified Files:
      Tag: TextIndexDS9-branch
Log Message:
Checkpointing my changes for us (Casey & Barry) to work on next week.
This doesn't actually make the ZMI work for ZCTextIndex but it gets a
little closer.  Of course, I could be all wrong. ;)

Specific changes:

ZCTextIndex.meta_type: changed to 'ZCTextIndex' from 'RelevanceIndex'
because otherwise when I selected 'RelevanceIndex' under the Indexes
tag in the catalog object, I got an error that it didn't know how to
create ZCTextIndex type objects.

__init__(): Added an `id' argument between self and extra.  Seems like
the publisher really wants to pass in an id here (as observed in the
TextIndex class).  Squirrel id away on self.

manage_addLexiconForm, manage_addLexicon(): The start of ZMI support
for creating lexicons.  Not finished.

=== Products/ZCTextIndex/ZCTextIndex.py => ===
     __implements__ = PluggableIndexInterface
-    meta_type = 'RelevanceIndex'
+    meta_type = 'ZCTextIndex'
     manage_options= (
         {'label': 'Settings', 'action': 'manage_main'},
-    def __init__(self, extra, caller):
+    def __init__(self, id, extra, caller):
+        self.id = id
         self._fieldname = extra.doc_attr
         lexicon = getattr(caller, extra.lexicon_id, None)
@@ -88,3 +89,19 @@
                                 REQUEST, RESPONSE, REQUEST.URL3)
 manage_addZCTextIndexForm = DTMLFile('dtml/addZCTextIndex', globals())
+manage_addLexiconForm = DTMLFile('dtml/addLexicon', globals())
+def manage_addLexicon(self, id, title, splitter=None, normalizer=None,
+                      stopword=None, REQUEST=None):
+    elements = []
+    if splitter:
+        elements.append(Lexicon.Splitter())
+    if normalizer:
+        elements.append(CaseNormalizer())
+    if stopwords:
+        elements.append(StopWordRemover())
+    lexicon = Lexicon(*elements)
+    self._setObject(id, lexicon)
+    if REQUEST is not None:
+        return self.manage_main(self, REQUEST, update_menu=1)