[Zope-Checkins] CVS: Zope2 - UnIndex.py:1.3 util.py:1.4

andreas@serenade.digicool.com andreas@serenade.digicool.com
Fri, 1 Jun 2001 14:53:41 -0400


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

Modified Files:
	UnIndex.py util.py 
Log Message:
- added "query_options" parameter to all index types
- made parseIndexRequest much more smarter in parsing the request parameter



--- Updated File UnIndex.py in package Zope2 --
--- UnIndex.py	2001/05/30 15:57:36	1.2
+++ UnIndex.py	2001/06/01 18:53:40	1.3
@@ -108,7 +108,6 @@
 class UnIndex(Persistent, Implicit):
     """UnIndex object interface"""
 
-    meta_type = 'Field Index'
 
     def __init__(self, id, ignore_ex=None, call_methods=None):
         """Create an unindex
@@ -378,7 +377,8 @@
 
         """
 
-        record = parseIndexRequest(request,self.id)
+
+        record = parseIndexRequest(request, self.id, self.query_options)
         if record.keys==None: return None
 
         index = self._index

--- Updated File util.py in package Zope2 --
--- util.py	2001/06/01 16:50:06	1.3
+++ util.py	2001/06/01 18:53:40	1.4
@@ -124,12 +124,13 @@
 
     ParserException = 'IndexRequestParseError'
 
-    def __init__(self,request,iid): 
+    def __init__(self,request,iid,options=[]): 
         """ parse a request  from the ZPublisher and return a uniform
         datastructure back to the _apply_index() method of the index
 
           request -- the request dictionary send from the ZPublisher
           iid     -- Id of index
+          options -- a list of options the index is interested in 
         """
 
         self.id         = iid
@@ -137,18 +138,12 @@
 
         if not request.has_key(iid): return
 
+        # We keep this for backward compatility
         if request.has_key(iid+'_usage'):
             self.usage = request[iid+'_usage']
 
-        if request.has_key(iid+'_operator'):
-            self.operator = request[iid+'_operator']
-
         keys = request[iid]
 
-
-        # This check checks if the object is an instance of
-        # Record - This check is lame and should be fixed !
-
         if type(keys) == InstanceType:
             """ query is of type record """
             record = keys
@@ -163,23 +158,28 @@
                 self.keys = [keys.strip()]
             elif type(keys) == ListType:
                 self.keys = keys
+
+            for op in options:
+                if op in ["query"]: continue 
 
-            for k in dir(record):
-                if not k in ['query','operator']: 
+                if hasattr(record,op):
                     setattr(self,k,getattr(record,k))
 
+
         elif type(keys)==DictType:
             """ query is a dictionary containing all parameters """
-
+    
             query = keys.get("query",[])
             if type(query) in [TupleType,ListType]:
                 self.keys = query
             else:
                 self.keys = [ query ]
 
-            for k,v in keys.items():
-                if k in ["query"]: continue
-                setattr(self,k,v)
+            for op in  options:         
+                if op in ["query"]: continue
+
+                if keys.has_key(op):
+                    setattr(self,op,keys[op])
  
 
         else:
@@ -189,17 +189,11 @@
                 self.keys  = keys
             else:
                 self.keys = [keys]
-
-            if hasattr(request, 'keys'):
-                # Look through the entire request for extra parameters.
-                # This is expensive!
-                params = filter(lambda x,id=self.id: x.startswith(id+'_'),
-                                request.keys())
 
-                params = map(lambda x,id=self.id: x[len(id)+1:],params)
+            for op in options:
+                if request.has_key(iid+"_"+op):
+                    setattr(self,op,request[iid+"_"+op])
 
-                for p in params: 
-                    setattr(self,p,request[self.id+'_'+p])
 
         if self.keys != None:
             self.keys = filter(lambda x: len(str(x))>0 , self.keys)
@@ -219,7 +213,7 @@
 
 def test():
 
-    r  = parseIndexRequest({'path':{'query':"xxxx","level":2,"operator":'and'}},'path')
+    r  = parseIndexRequest({'path':{'query':"xxxx","level":2,"operator":'and'}},'path',['query',"level","operator"])
     for k in dir(r):
         print k,getattr(r,k)