[Checkins] SVN: Zope/branches/2.11/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py Port improvements from ExtendedPathIndex:

Martijn Pieters mj at zopatista.com
Sat Dec 13 13:48:01 EST 2008


Log message for revision 94035:
  Port improvements from ExtendedPathIndex:
  
  - The level < 0 case is basically the union of all searches for levels 0
    through to max. Just call search() for each level and use multiunion on all
    the results.
  - Shorten the 'no-such-path' detection to one test.
  

Changed:
  U   Zope/branches/2.11/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py

-=-
Modified: Zope/branches/2.11/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py
===================================================================
--- Zope/branches/2.11/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py	2008-12-13 18:46:10 UTC (rev 94034)
+++ Zope/branches/2.11/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py	2008-12-13 18:48:01 UTC (rev 94035)
@@ -21,7 +21,7 @@
 from OFS.SimpleItem import SimpleItem
 from BTrees.IOBTree import IOBTree
 from BTrees.OOBTree import OOBTree
-from BTrees.IIBTree import IITreeSet, IISet, intersection, union
+from BTrees.IIBTree import IITreeSet, IISet, intersection, union, multiunion
 from BTrees.Length import Length
 from zope.interface import implements
 
@@ -168,6 +168,12 @@
         else:
             level = int(path[1])
             path  = path[0]
+        
+        if level < 0:
+            # Search at every level, return the union of all results
+            return multiunion(
+                [self.search(path, level) 
+                 for level in xrange(self._depth + 1)])
 
         comps = filter(None, path.split('/'))
 
@@ -175,22 +181,9 @@
             return IISet(self._unindex.keys())
 
         results = None
-        if level >= 0:
-            for i, comp in enumerate(comps):
-                if not self._index.has_key(comp): return IISet()
-                if not self._index[comp].has_key(level+i): return IISet()
-                results = intersection(results, self._index[comp][level+i])
-
-        else:
-            for level in range(self._depth + 1):
-                ids = None
-                for i, comp in enumerate(comps):
-                    try:
-                        ids = intersection(ids, self._index[comp][level+i])
-                    except KeyError:
-                        break
-                else:    
-                    results = union(results, ids)
+        for i, comp in enumerate(comps):
+            if not self._index.get(comp, {}).has_key(level+i): return IISet()
+            results = intersection(results, self._index[comp][level+i])
         return results
 
     def numObjects(self):



More information about the Checkins mailing list