[Zope-Checkins] CVS: Zope2 - PathIndex.py:1.1.2.11
andreas@serenade.digicool.com
andreas@serenade.digicool.com
Fri, 18 May 2001 14:35:03 -0400
Update of /cvs-repository/Zope2/lib/python/Products/PluginIndexes/PathIndex
In directory serenade:/tmp/cvs-serv2884/PathIndex
Modified Files:
Tag: ajung-dropin-registry
PathIndex.py
Log Message:
added support for _operator
minor changes
--- Updated File PathIndex.py in package Zope2 --
--- PathIndex.py 2001/05/17 12:12:15 1.1.2.10
+++ PathIndex.py 2001/05/18 18:35:02 1.1.2.11
@@ -127,12 +127,18 @@
def __init__(self,id,caller=None):
self.id = id
+
+ # experimental code for specifing the operator
+ self.operators = ['or','and']
+ self.useOperator = 'or'
+
self.clear()
def clear(self):
""" clear everything """
+ self._depth = 0
self._index = OOBTree()
self._unindex = IOBTree()
@@ -151,6 +157,8 @@
self._index[comp][level] = IISet()
self._index[comp][level].insert(id)
+
+ if level > self._depth: self._depth = level
# reverse index
if not self._unindex.has_key(id):
@@ -236,11 +244,29 @@
return res
else:
- raise exceptions.RuntimeError, "level<0 not supported yet"
-
- return res
+
+ results = None
+
+ for level in range(0,self._depth):
+
+ ids = None
+ error = 0
+
+ for cn in range(0,len(comps)):
+ comp = comps[cn]
+
+ try:
+ ids = intersection(ids,self._index[comp][level+cn])
+ except:
+ error = 1
+
+ if error==0:
+ results = union(results,ids)
+
+ return results
+
def __len__(self):
""" len """
return len(self._index)
@@ -294,21 +320,37 @@
level = request.get("path_level",0)
+ # experimental code for specifing the operator
+
+ if request.has_key(self.id+"_operator"):
+ # check if someone overrides the "or" parameter
+ # for combining search results
+ operator = request[id+"_operator"].lower()
+ if not operator in self.operators :
+ raise exepctions.RuntimeError,"operator not valid: %s" % operator
+ else:
+ operator = self.useOperator
+
+ # depending on the operator we use intersection of union
+ if operator=="or": set_func = union
+ else: set_func = intersection
+
+
+
if type(keys) is StringType:
if not keys or not string.strip(keys):
return None
keys = [keys]
- res = IISet()
+ res = None
for k in keys:
# if k[0]=="/": level = 0
rows = self.search(k,level)
+ res = set_func(res,rows)
- for r in rows:
- res.insert(r)
if len(res)>0:
return res, (self.id,)