Skip to content

Commit

Permalink
avoid hardcoding two-sort-index restriction in two places
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed Apr 7, 2012
1 parent 48a2db9 commit ed2136e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Products/ZCatalog/Catalog.py
Expand Up @@ -666,8 +666,10 @@ def sortResults(self, rs, sort_index, reverse=False, limit=None,
# result set in sorted order if merge is true otherwise
# returns a list of (sortkey, uid, getter_function) tuples
index2 = None
sort_index_length = 1
if isinstance(sort_index, list):
if len(sort_index) > 1:
sort_index_length = len(sort_index)
if sort_index_length > 1:
index2 = sort_index[1]
sort_index = sort_index[0]
_self__getitem__ = self.__getitem__
Expand Down Expand Up @@ -713,12 +715,14 @@ def sortResults(self, rs, sort_index, reverse=False, limit=None,
# determine sort_spec
if isinstance(reverse, list):
sort_spec = [r and -1 or 1 for r in reverse]
# limit to current maximum of two indexes
sort_spec = sort_spec[:2]
# limit to current maximum of sort indexes
sort_spec = sort_spec[:sort_index_length]
# use first sort order for choosing the algorithm
reverse = reverse[0]
else:
sort_spec = [reverse and -1 or 1, reverse and -1 or 1]
sort_spec = []
for i in xrange(sort_index_length):
sort_spec.append(reverse and -1 or 1)

if merge and limit is None and (
rlen > (len(sort_index) * (rlen / 100 + 1))):
Expand Down

0 comments on commit ed2136e

Please sign in to comment.