[Zope-Checkins] CVS: Zope2 - Lexicon.py:1.1.2.6 TextIndex.py:1.1.2.9

andreas@serenade.digicool.com andreas@serenade.digicool.com
Thu, 17 May 2001 14:28:27 -0400


Update of /cvs-repository/Zope2/lib/python/Products/PluginIndexes/TextIndex
In directory serenade:/tmp/cvs-serv31121/TextIndex

Modified Files:
      Tag: ajung-dropin-registry
	Lexicon.py TextIndex.py 
Log Message:




--- Updated File Lexicon.py in package Zope2 --
--- Lexicon.py	2001/05/16 18:31:10	1.1.2.5
+++ Lexicon.py	2001/05/17 18:27:57	1.1.2.6
@@ -114,7 +114,6 @@
 
     def __init__(self, stop_syn=None,useSplitter=None):
 
-        print "init lexicon"
 
         self.clear()
         if stop_syn is None:

--- Updated File TextIndex.py in package Zope2 --
--- TextIndex.py	2001/05/16 18:31:10	1.1.2.8
+++ TextIndex.py	2001/05/17 18:27:57	1.1.2.9
@@ -98,35 +98,33 @@
 import operator
 
 from Globals import Persistent,DTMLFile
-from Acquisition import Implicit
 from zLOG import LOG, ERROR
-from types import *
 from OFS.SimpleItem import SimpleItem
+from Acquisition import Implicit
+from Products.PluginIndexes.common.ResultList import ResultList
+from Products.PluginIndexes import PluggableIndex       
 
 from BTrees.IOBTree import IOBTree
 from BTrees.OIBTree import OIBTree
 from BTrees.IIBTree import IIBTree, IIBucket, IISet, IITreeSet
 from BTrees.IIBTree import difference, weightedIntersection
-
-
-from Products.PluginIndexes import PluggableIndex 
-from Products.PluginIndexes.common.ResultList import ResultList
-import Splitter
-from Lexicon  import Lexicon, stop_word_dict
 
+from Lexicon import Lexicon
+from Splitter import Splitter
 
+from Splitter import availableSplitters
 
-AndNot = 'andnot'
-And = 'and'
-Or = 'or'
-Near = '...'
-QueryError = 'TextIndex.QueryError'
+from types import *
 
+AndNot      = 'andnot'
+And         = 'and'
+Or          = 'or'
+Near        = '...'
+QueryError  = 'TextIndex.QueryError'
 
 
 class TextIndex(PluggableIndex.PluggableIndex, Persistent,
-    Implicit, SimpleItem):
-
+     Implicit, SimpleItem):
     """Full-text index.
 
     There is a ZCatalog UML model that sheds some light on what is
@@ -145,18 +143,21 @@
     This isn't exactly how things are represented in memory, many
     optimizations happen along the way."""
 
+    meta_type = 'Text Index'
+
     __implements__ = (PluggableIndex.PluggableIndexInterface,)
 
     meta_type='TextIndex'
-
+ 
     manage_options = (
-        SimpleItem.manage_options + 
+        SimpleItem.manage_options +
         (
         {'label': 'Vocabulary',           # TAB: Contents
          'action': 'manage_vocabulary',
          'help': ('OFSP','ObjectManager_Contents.stx')},)
     )
 
+
     def __init__(self, id, ignore_ex=None, call_methods=None, lexicon=None):
         """Create an index
 
@@ -178,21 +179,21 @@
         self.ignore_ex = ignore_ex
         self.call_methods = call_methods
 
+
         # Default Splitter
-        self.availableSplitters = Splitter.availableSplitters
-        print "SPLITTERS:",self.availableSplitters
+        self.availableSplitters = availableSplitters
         self.useSplitter        = self.availableSplitters[0][0]
 
-        # Default text index operator (should be visible to mgmt
+        # Default text index operator (should be visible to ZMI)
         self.operators = { 'andnot':AndNot, 'and':And,
-                           'near':Near, 'or':Or }
-        self.useOperator  = 'and'
+                            'near':Near, 'or':Or }
+        self.useOperator  = 'or'
 
         self.clear()
         
         if lexicon is None:
             ## if no lexicon is provided, create a default one
-            self._lexicon = Lexicon(useSplitter=self.useSplitter)
+            self._lexicon = Lexicon()
         else:
             # We need to hold a reference to the lexicon, since we can't
             # really change lexicons.
@@ -350,12 +351,11 @@
                 source = str(source())
             else:
                 source = str(source)
-        except AttributeError:
+        except (AttributeError, TypeError):
             return 0
         
         lexicon = self.getLexicon(self._lexicon)
-#        splitter=lexicon.Splitter
-        splitter = Splitter.getSplitter(self.useSplitter)
+        splitter=lexicon.Splitter
 
         wordScores = OIBTree()
         last = None
@@ -514,11 +514,30 @@
         # Changed for 2.4
         # We use the default operator that can me managed via the ZMI
   
+        
+        operators = {
+            'andnot':AndNot,
+            'and':And,
+            'near':Near,
+            'or':Or
+            }
+
+        query_operator = Or
+
+        print '-'*80
+        print 'old_code:',query_operator,len(query_operator),type(query_operator)
+        print 'new_code:',self.operators[self.useOperator],len(self.operators[self.useOperator]),type(self.operators[self.useOperator])
+        print 'equal', self.operators[self.useOperator]==Or
+        assert  self.operators[self.useOperator]==Or
+
         query_operator = self.operators[self.useOperator]
 
+        # We default to 'or' if we aren't passed an operator in the request
+        # or if we can't make sense of the passed-in operator
+
         if request.has_key('textindex_operator'):
             op=string.lower(str(request['textindex_operator']))
-            query_operator = self.operators.get(op, query_operator)
+            query_operator = operators.get(op, query_operator)
 
         if type(keys) is StringType:
             if not keys or not string.strip(keys):
@@ -532,6 +551,7 @@
             if not key:
                 continue
 
+            print key,query_operator
             b = self.query(key, query_operator).bucket()
             w, r = weightedIntersection(r, b)
 
@@ -677,26 +697,6 @@
         return query[0]
 
 
-    def manage_vocabulary(self):
-        """ """
-        return ""
-
-
-    def manage_setPreferences(self,splitter,text_operator,
-                              REQUEST=None,RESPONSE=None,URL1=None):
-        """ preferences of TextIndex """
-
-        self.useSplitter = splitter
-        self.useOperator = text_operator
-
-        if RESPONSE:
-            RESPONSE.redirect(URL1 + '/manage_main?manage_tabs_message=Preferences%20saved')    
-
-    index_html = DTMLFile('dtml/index', globals())
-
-    manage_workspace = DTMLFile('dtml/manageTextIndex', globals())
-
-
 def parse(s):
     """Parse parentheses and quotes"""
     l = []
@@ -794,8 +794,6 @@
          splitted = filter(None, split(s))
 
      return splitted
-
-