Log message for revision 115340:
  Move index restriction to _sorted_search_indexes method
  

Changed:
  U   Zope/trunk/src/Products/ZCatalog/Catalog.py
  U   Zope/trunk/src/Products/ZCatalog/tests/test_catalog.py

-=-
Modified: Zope/trunk/src/Products/ZCatalog/Catalog.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/Catalog.py 2010-08-01 16:36:39 UTC (rev 
115339)
+++ Zope/trunk/src/Products/ZCatalog/Catalog.py 2010-08-01 16:51:14 UTC (rev 
115340)
@@ -470,7 +470,8 @@
 
     def _sorted_search_indexes(self, query):
         # Simple implementation doing no ordering.
-        return self.indexes.keys()
+        query_keys = query.keys()
+        return [i for i in self.indexes.keys() if i in query_keys]
 
     def search(self, query, sort_index=None, reverse=0, limit=None, merge=1):
         """Iterate through the indexes, applying the query to each one. If
@@ -500,11 +501,6 @@
         cr.start()
 
         for i in self._sorted_search_indexes(query):
-            if i not in query_keys:
-                # Do not ask indexes to restrict the result, which aren't
-                # part of the query
-                continue
-
             index = self.getIndex(i)
             _apply_index = getattr(index, "_apply_index", None)
             if _apply_index is None:

Modified: Zope/trunk/src/Products/ZCatalog/tests/test_catalog.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/tests/test_catalog.py      2010-08-01 
16:36:39 UTC (rev 115339)
+++ Zope/trunk/src/Products/ZCatalog/tests/test_catalog.py      2010-08-01 
16:51:14 UTC (rev 115340)
@@ -199,7 +199,6 @@
         att3 = KeywordIndex('att3')
         num = FieldIndex('num')
 
-
         self._catalog.addIndex('att1', att1)
         self._catalog.addIndex('att2', att2)
         self._catalog.addIndex('att3', att3)
@@ -285,6 +284,20 @@
     # getIndexDataForRID
     # make_query
     # _sorted_search_indexes
+
+    def test_sorted_search_indexes_empty(self):
+        result = self._catalog._sorted_search_indexes({})
+        self.assertEquals(len(result), 0)
+
+    def test_sorted_search_indexes_one(self):
+        result = self._catalog._sorted_search_indexes({'att1': 'a'})
+        self.assertEquals(result, ['att1'])
+
+    def test_sorted_search_indexes_many(self):
+        query = {'att1': 'a', 'att2': 'b', 'num': 1}
+        result = self._catalog._sorted_search_indexes(query)
+        self.assertEquals(set(result), set(['att1', 'att2', 'num']))
+
     # search
     # sortResults
     # _get_sort_attr

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
https://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to