[Zope-Checkins] SVN: Zope/trunk/ Forward-port fix for LP #143655 from the 2.12 branch.

Tres Seaver tseaver at palladion.com
Mon Apr 12 12:43:47 EDT 2010


Log message for revision 110756:
  Forward-port fix for LP #143655 from the 2.12 branch.

Changed:
  U   Zope/trunk/doc/CHANGES.rst
  U   Zope/trunk/src/Products/PluginIndexes/PathIndex/PathIndex.py
  U   Zope/trunk/src/Products/PluginIndexes/PathIndex/tests/testPathIndex.py

-=-
Modified: Zope/trunk/doc/CHANGES.rst
===================================================================
--- Zope/trunk/doc/CHANGES.rst	2010-04-12 16:42:52 UTC (rev 110755)
+++ Zope/trunk/doc/CHANGES.rst	2010-04-12 16:43:47 UTC (rev 110756)
@@ -153,6 +153,8 @@
 Bugs Fixed
 ++++++++++
 
+- LP #143655:  don't prevent sorting using a path index.
+
 - LP #142478:  normalize terms passed to ``PLexicon.queryLexicon`` using
   the lexicon's pipeline (e.g., case flattening, stop word removal, etc.)
 

Modified: Zope/trunk/src/Products/PluginIndexes/PathIndex/PathIndex.py
===================================================================
--- Zope/trunk/src/Products/PluginIndexes/PathIndex/PathIndex.py	2010-04-12 16:42:52 UTC (rev 110755)
+++ Zope/trunk/src/Products/PluginIndexes/PathIndex/PathIndex.py	2010-04-12 16:43:47 UTC (rev 110756)
@@ -31,6 +31,7 @@
 from Products.PluginIndexes.common import safe_callable
 from Products.PluginIndexes.common.util import parseIndexRequest
 from Products.PluginIndexes.interfaces import IPathIndex
+from Products.PluginIndexes.interfaces import ISortIndex
 from Products.PluginIndexes.interfaces import IUniqueValueIndex
 
 LOG = getLogger('Zope.PathIndex')
@@ -51,7 +52,7 @@
     - the value is a mapping 'level of the path component' to
       'all docids with this path component on this level'
     """
-    implements(IPathIndex, IUniqueValueIndex)
+    implements(IPathIndex, IUniqueValueIndex, ISortIndex)
 
     meta_type="PathIndex"
     query_options = ('query', 'level', 'operator')
@@ -213,6 +214,18 @@
                 for key in self._index.keys():
                     yield key
 
+    # ISortIndex implementation
+
+    def keyForDocument(self, documentId):
+        """ See ISortIndex.
+        """
+        return self._unindex.get(documentId)
+
+    def documentToKeyMap(self):
+        """ See ISortIndex.
+        """
+        return self._unindex
+
     # Helper methods
 
     def _insertEntry(self, comp, id, level):

Modified: Zope/trunk/src/Products/PluginIndexes/PathIndex/tests/testPathIndex.py
===================================================================
--- Zope/trunk/src/Products/PluginIndexes/PathIndex/tests/testPathIndex.py	2010-04-12 16:42:52 UTC (rev 110755)
+++ Zope/trunk/src/Products/PluginIndexes/PathIndex/tests/testPathIndex.py	2010-04-12 16:43:47 UTC (rev 110756)
@@ -63,15 +63,15 @@
             return self._getTargetClass()(id, caller)
         return self._getTargetClass()(id)
 
-    def test_class_conforms_to_IPathIndex(self):
-        from Products.PluginIndexes.interfaces import IPathIndex
+    def test_class_conforms_to_IPluggableIndex(self):
+        from Products.PluginIndexes.interfaces import IPluggableIndex
         from zope.interface.verify import verifyClass
-        verifyClass(IPathIndex, self._getTargetClass())
+        verifyClass(IPluggableIndex, self._getTargetClass())
 
-    def test_instance_conforms_to_IPathIndex(self):
-        from Products.PluginIndexes.interfaces import IPathIndex
+    def test_instance_conforms_to_IPluggableIndex(self):
+        from Products.PluginIndexes.interfaces import IPluggableIndex
         from zope.interface.verify import verifyObject
-        verifyObject(IPathIndex, self._makeOne())
+        verifyObject(IPluggableIndex, self._makeOne())
 
     def test_class_conforms_to_IUniqueValueIndex(self):
         from Products.PluginIndexes.interfaces import IUniqueValueIndex
@@ -83,6 +83,26 @@
         from zope.interface.verify import verifyObject
         verifyObject(IUniqueValueIndex, self._makeOne())
 
+    def test_class_conforms_to_ISortIndex(self):
+        from Products.PluginIndexes.interfaces import ISortIndex
+        from zope.interface.verify import verifyClass
+        verifyClass(ISortIndex, self._getTargetClass())
+
+    def test_instance_conforms_to_ISortIndex(self):
+        from Products.PluginIndexes.interfaces import ISortIndex
+        from zope.interface.verify import verifyObject
+        verifyObject(ISortIndex, self._makeOne())
+
+    def test_class_conforms_to_IPathIndex(self):
+        from Products.PluginIndexes.interfaces import IPathIndex
+        from zope.interface.verify import verifyClass
+        verifyClass(IPathIndex, self._getTargetClass())
+
+    def test_instance_conforms_to_IPathIndex(self):
+        from Products.PluginIndexes.interfaces import IPathIndex
+        from zope.interface.verify import verifyObject
+        verifyObject(IPathIndex, self._makeOne())
+
     def test_ctor(self):
         index = self._makeOne()
         self.assertEqual(index.id, 'path')
@@ -417,6 +437,25 @@
         self.assertEqual(results['cc'],
                          len([x for x in DUMMIES.values() if 'cc' in x.path]))
 
+    def test_keyForDocument_miss(self):
+        index = self._makeOne()
+        self.assertEqual(index.keyForDocument(1), None)
+
+    def test_keyForDocument_hit(self):
+        index = self._makeOne()
+        _populateIndex(index)
+        self.assertEqual(index.keyForDocument(1), DUMMIES[1].path)
+
+    def test_documentToKeyMap_empty(self):
+        index = self._makeOne()
+        self.assertEqual(dict(index.documentToKeyMap()), {})
+
+    def test_documentToKeyMap_filled(self):
+        index = self._makeOne()
+        _populateIndex(index)
+        self.assertEqual(dict(index.documentToKeyMap()),
+                         dict([(k, v.path) for k, v in DUMMIES.items()]))
+
     def test__search_empty_index_string_query(self):
         index = self._makeOne()
         self.assertEqual(list(index._search('/xxx')), [])



More information about the Zope-Checkins mailing list