[Checkins] SVN: Products.ZCatalog/trunk/ Change some internal wiring and let multiple sort_on values pass through. `Catalog.sortResults` is now called with a list of search indexes. Currently additional indexes are ignored.
Hano Schlichting
cvs-admin at zope.org
Sun Mar 25 21:16:10 UTC 2012
Log message for revision 124730:
Change some internal wiring and let multiple sort_on values pass through. `Catalog.sortResults` is now called with a list of search indexes. Currently additional indexes are ignored.
Changed:
U Products.ZCatalog/trunk/CHANGES.txt
U Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
U Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py
-=-
Modified: Products.ZCatalog/trunk/CHANGES.txt
===================================================================
--- Products.ZCatalog/trunk/CHANGES.txt 2012-03-25 20:56:47 UTC (rev 124729)
+++ Products.ZCatalog/trunk/CHANGES.txt 2012-03-25 21:16:06 UTC (rev 124730)
@@ -4,6 +4,9 @@
3.0 (unreleased)
----------------
+- Change some internal wiring and let multiple sort_on values pass through.
+ `Catalog.sortResults` is now called with a list of search indexes.
+
- Added support for `not` queries in field and keyword indexes. Both
restrictions of normal queries and range queries are supported, as well as
purely exclusive queries. For example:
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py 2012-03-25 20:56:47 UTC (rev 124729)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py 2012-03-25 21:16:06 UTC (rev 124730)
@@ -671,6 +671,9 @@
# proportion of the time to perform an indexed search.
# Try to avoid all non-local attribute lookup inside
# those loops.
+ if isinstance(sort_index, list):
+ # TODO: ignore multiple sort indexes for now
+ sort_index = sort_index[0]
_intersection = intersection
_self__getitem__ = self.__getitem__
index_key_map = sort_index.documentToKeyMap()
@@ -861,20 +864,25 @@
return kw.get("sort_%s" % attr, None)
def _getSortIndex(self, args):
- """Returns a search index object or None."""
- sort_index_name = self._get_sort_attr("on", args)
- if sort_index_name is not None:
+ """Returns a list of search index objects or None."""
+ sort_index_names = self._get_sort_attr("on", args)
+ if sort_index_names is not None:
# self.indexes is always a dict, so get() w/ 1 arg works
- sort_index = self.indexes.get(sort_index_name)
- if sort_index is None:
- raise CatalogError('Unknown sort_on index (%s)' %
- sort_index_name)
- else:
- if not hasattr(sort_index, 'documentToKeyMap'):
- raise CatalogError(
- 'The index chosen for sort_on (%s) is not capable of '
- 'being used as a sort index.' % sort_index_name)
- return sort_index
+ sort_indexes = []
+ if not isinstance(sort_index_names, (list, tuple)):
+ sort_index_names = [sort_index_names]
+ for name in sort_index_names:
+ sort_index = self.indexes.get(name)
+ if sort_index is None:
+ raise CatalogError('Unknown sort_on index: %s' %
+ repr(name))
+ else:
+ if not hasattr(sort_index, 'documentToKeyMap'):
+ raise CatalogError('The index chosen for sort_on is not '
+ 'capable of being used as a sort index: '
+ '%s' % repr(name))
+ sort_indexes.append(sort_index)
+ return sort_indexes[0]
else:
return None
@@ -895,16 +903,16 @@
args = REQUEST
else:
args = CatalogSearchArgumentsMap(REQUEST, kw)
- sort_index = self._getSortIndex(args)
+ sort_indexes = self._getSortIndex(args)
sort_limit = self._get_sort_attr('limit', args)
reverse = 0
- if sort_index is not None:
+ if sort_indexes is not None:
order = self._get_sort_attr("order", args)
if (isinstance(order, str) and
order.lower() in ('reverse', 'descending')):
reverse = 1
# Perform searches with indexes and sort_index
- return self.search(args, sort_index, reverse, sort_limit, _merge)
+ return self.search(args, sort_indexes, reverse, sort_limit, _merge)
__call__ = searchResults
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py 2012-03-25 20:56:47 UTC (rev 124729)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py 2012-03-25 21:16:06 UTC (rev 124730)
@@ -499,6 +499,14 @@
self.assertEqual(len(a), upper,
'length should be %s, its %s' % (upper, len(a)))
+ def DISABLED_test_sort_on_two(self):
+ upper = self.upper
+ a = self._catalog(sort_on=('att1', 'num'), att1='att1')
+ self.assertEqual(len(a), upper,
+ 'length should be %s, its %s' % (upper, len(a)))
+ for x in range(self.upper):
+ self.assertEqual(a[x].num, x)
+
def testKeywordIndexWithMinRange(self):
a = self._catalog(att3={'query': 'att', 'range': 'min'})
self.assertEqual(len(a), self.upper)
More information about the checkins
mailing list