[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/common - PluggableIndex.py:1.7.42.1 UnIndex.py:1.15.22.1

Casey Duncan casey@zope.com
Thu, 5 Dec 2002 16:07:16 -0500


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

Modified Files:
      Tag: casey-zcatalog-speedup-branch
	PluggableIndex.py UnIndex.py 
Log Message:
Cleaned up PlugInIndex interfaces to bring them closer to reality
Added SortIndex and UniqueValueIndex interfaces, assigned them to the proper indexes
Added documentToKeyMap method to UnIndex base class. This is now used in the optimized ZCatalog sort code instead of keyForDocument


=== Zope/lib/python/Products/PluginIndexes/common/PluggableIndex.py 1.7 => 1.7.42.1 ===
--- Zope/lib/python/Products/PluginIndexes/common/PluggableIndex.py:1.7	Wed Aug 14 18:19:34 2002
+++ Zope/lib/python/Products/PluginIndexes/common/PluggableIndex.py	Thu Dec  5 16:07:16 2002
@@ -11,7 +11,7 @@
 #
 ##############################################################################
 
-"""Pluggable Index Base Class """
+"""Pluggable Index Interface"""
 __version__='$Revision$'[11:-2]
 
 import Interface
@@ -36,14 +36,6 @@
     def unindex_object(documentId):
         """Remove the documentId from the index."""
 
-    # XXX TextIndex does not implement uniqueValues().
-    def uniqueValues(name=None, withLengths=0):
-        """Returns the unique values for name.
-
-        If 'withLengths' is true, returns a sequence of tuples of
-        (value, length).
-        """
-
     def _apply_index(request, cid=''):
         """Apply the index to query parameters given in 'request'.
 
@@ -67,3 +59,34 @@
         records.  The second object is a tuple containing the names of
         all data fields used.
         """
+    
+    def numObjects():
+        """Return the number of indexed objects"""
+    
+    def clear():
+        """Empty the index"""
+        
+class UniqueValueIndex(PluggableIndexInterface):
+    """An index which can return lists of unique values contained in it"""
+    
+    def hasUniqueValuesFor(name):
+        """Return true if the index can return the unique values for name"""
+        
+    def uniqueValues(name=None, withLengths=0):
+        """Return the unique values for name.
+
+        If 'withLengths' is true, returns a sequence of tuples of
+        (value, length)."""
+
+class SortIndex(PluggableIndexInterface):
+    """An index which may be used to sort a set of document ids"""
+    
+    def keyForDocument(documentId):
+        """Return the sort key that cooresponds to the specified document id
+        
+        This method is no longer used by ZCatalog, but is left for backwards 
+        compatibility."""
+        
+    def documentToKeyMap():
+        """Return an object that supports __getitem__ and may be used to quickly
+        lookup the sort key given a document id"""


=== Zope/lib/python/Products/PluginIndexes/common/UnIndex.py 1.15 => 1.15.22.1 ===
--- Zope/lib/python/Products/PluginIndexes/common/UnIndex.py:1.15	Tue Oct  1 10:09:47 2002
+++ Zope/lib/python/Products/PluginIndexes/common/UnIndex.py	Thu Dec  5 16:07:16 2002
@@ -383,7 +383,7 @@
             return r, (self.id,)
 
     def hasUniqueValuesFor(self, name):
-        ' has unique values for column NAME '
+        """has unique values for column name"""
         if name == self.id:
             return 1
         else:
@@ -413,11 +413,15 @@
                 else:
                     l = len(set)
                 rl.append((i, l))
-            return tuple(rl)
+            return tuple(rl)        
 
     def keyForDocument(self, id):
+        # This method is superceded by documentToKeyMap
         return self._unindex[id]
-
+    
+    def documentToKeyMap(self):
+        return self._unindex
+    
     def items(self):
         items = []
         for k,v in self._index.items():