[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/PathIndex - PathIndex.py:1.35.8.2

Andreas Jung andreas at andreas-jung.com
Fri Aug 15 12:01:35 EDT 2003


Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/PathIndex
In directory cvs.zope.org:/tmp/cvs-serv21642/PathIndex

Modified Files:
      Tag: ajung-indexes-btrees-length-branch
	PathIndex.py 
Log Message:
- using counter instead of len() to determine the number of indexed object
- removed lot of garbage und really unneeded code


=== Zope/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py 1.35.8.1 => 1.35.8.2 ===
--- Zope/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py:1.35.8.1	Fri Aug 15 10:35:24 2003
+++ Zope/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py	Fri Aug 15 11:01:29 2003
@@ -13,24 +13,24 @@
 
 __version__ = '$Id$'
 
-from Products.PluginIndexes import PluggableIndex
-from Products.PluginIndexes.common.util import parseIndexRequest
-from Products.PluginIndexes.common import safe_callable
+import warnings
+from types import StringType, ListType, TupleType
 
 from Globals import Persistent, DTMLFile
-from Acquisition import Implicit
-
+from OFS.SimpleItem import SimpleItem
 from BTrees.IOBTree import IOBTree
 from BTrees.OOBTree import OOBTree
 from BTrees.IIBTree import IITreeSet, IISet, intersection, union
-from OFS.SimpleItem import SimpleItem
+from BTrees.Length import Length
 from zLOG import LOG, ERROR
-from types import StringType, ListType, TupleType
-import warnings
+
+from Products.PluginIndexes import PluggableIndex
+from Products.PluginIndexes.common.util import parseIndexRequest
+from Products.PluginIndexes.common import safe_callable
 
 _marker = []
 
-class PathIndex(Persistent, Implicit, SimpleItem):
+class PathIndex(Persistent, SimpleItem):
     """ A path index stores all path components of the physical
     path of an object:
 
@@ -67,6 +67,7 @@
         self._depth = 0
         self._index = OOBTree()
         self._unindex = IOBTree()
+        self._length = Length(0)
 
     def insertEntry(self, comp, id, level):
         """Insert an entry.
@@ -110,6 +111,9 @@
         if isinstance(path, (ListType, TupleType)):
             path = '/'+ '/'.join(path[1:])
         comps = filter(None, path.split('/'))
+       
+        if not self._unindex.has_key(docid):
+            self._length.change(1)
 
         for i in range(len(comps)):
             self.insertEntry(comps[i], docid, i)
@@ -143,6 +147,7 @@
                     'Attempt to unindex document'
                     ' with id %s failed' % docid)
 
+        self._length.change(-1)
         del self._unindex[docid]
 
     def search(self, path, default_level=0):
@@ -194,37 +199,22 @@
                     results = union(results,ids)
             return results
 
-    def __len__(self):
-        """ len """
-        # XXX REALLY inefficient
-        return len(self._index)
-
     def numObjects(self):
         """ return the number of indexed objects"""
-        # XXX REALLY inefficient
-        return len(self._unindex)
-
-    def keys(self):
-        """ return list of all path components """
-        # XXX Could this be lazy, does it need to be a list?
-        return list(self._index.keys())
-
-    def values(self):
-        # XXX Could this be lazy, does it need to be a list?
-        return list(self._index.values())
-
-    def items(self):
-        """ mapping path components : docids """
-        # XXX Could this be lazy, does it need to be a list?
-        return list(self._index.items())
+        try:
+            return self._length()
+        except AttributeError:        # backward compatibility
+            l = len(self._unindex)
+            self._length = Length(l)
+            return l
 
     def _apply_index(self, request, cid=''):
         """ hook for (Z)Catalog
-        request   mapping type (usually {"path": "..." }
-                  additionaly a parameter "path_level" might be passed
-                  to specify the level (see search())
+            'request' --  mapping type (usually {"path": "..." }
+             additionaly a parameter "path_level" might be passed
+             to specify the level (see search())
 
-        cid      ???
+            'cid' -- ???
         """
 
         record = parseIndexRequest(request,self.id,self.query_options)
@@ -236,11 +226,7 @@
                           "Please use a mapping object and the "
                           "'level' key to specify the operator." % cid)
 
-
-        # get the level parameter
         level    = record.get("level",0)
-
-        # experimental code for specifing the operator
         operator = record.get('operator',self.useOperator).lower()
 
         # depending on the operator we use intersection of union
@@ -248,7 +234,6 @@
         else: set_func = intersection
 
         res = None
-
         for k in record.keys:
             rows = self.search(k,level)
             res = set_func(res,rows)




More information about the Zope-Checkins mailing list