Back to index

plone3  3.1.7
Classes | Functions
AdvancedQuery.sorting Namespace Reference

Classes

class  _SortAccess
class  Sorter
class  IndexSorter

Functions

def sort
def _sort
def normSortSpecs

Function Documentation

def AdvancedQuery.sorting._sort (   seq,
  sortSpecs,
  withSortValues 
) [private]

Definition at line 49 of file sorting.py.

00049 
00050 def _sort(seq, sortSpecs, withSortValues):
00051   # Note: "set" is an "IISet" or "IITreeSet"
00052   ns = len(seq)
00053   if ns == 1 and not withSortValues: yield seq.keys()[0]; return
00054 
00055   if not sortSpecs:
00056     wrap = withSortValues and (lambda did, e=(): (e, did)) or (lambda did: did)
00057     for s in seq.keys(): yield wrap(s)
00058     return
00059 
00060   sortSpecs = sortSpecs[:]
00061   sortSpec = sortSpecs.pop(0)
00062   for value, subseq in sortSpec.group(seq):
00063     subseq = _sort(subseq, sortSpecs, withSortValues)
00064     if withSortValues:
00065       for sv, did in subseq: yield (value,) + sv, did
00066     else:
00067       for did in subseq: yield did
00068 

Here is the call graph for this function:

Here is the caller graph for this function:

def AdvancedQuery.sorting.normSortSpecs (   specs,
  withSortValue,
  cat 
)
normalize sort specs *specs* and *withSortValue*.

*specs* is a sequence of sort specifications.
A sort specification is either a 'RankSpec', an index name
or a pair index name + sorting order ('asc'/'desc').

If 'withSortValue' is '_notPassed', then it is set to 'True',
is *specs* contains a 'RankSpec', otherwise to 'False'.

Definition at line 129 of file sorting.py.

00129 
00130 def normSortSpecs(specs, withSortValue, cat):
00131   '''normalize sort specs *specs* and *withSortValue*.
00132 
00133   *specs* is a sequence of sort specifications.
00134   A sort specification is either a 'RankSpec', an index name
00135   or a pair index name + sorting order ('asc'/'desc').
00136 
00137   If 'withSortValue' is '_notPassed', then it is set to 'True',
00138   is *specs* contains a 'RankSpec', otherwise to 'False'.
00139   '''
00140   l= []; withValue = False
00141   for s in specs:
00142     if hasattr(s, '_prepare'): s = s._prepare(cat); withValue = True
00143     else:
00144       if isinstance(s, tuple): si,so= s
00145       else: si=s; so= 'asc'
00146       i= cat.indexes[si]
00147       # ensure, the index supports sorting
00148       if not hasattr(i,'documentToKeyMap'):
00149         raise ValueError,'Index not adequate for sorting: %s' % si
00150       # check whether we should reverse the order
00151       so= so.lower()
00152       if so in ('asc', 'ascending'): sr= 0
00153       elif so in ('desc', 'descending', 'reverse'): sr= 1
00154       s = IndexSorter(i, sr)
00155     l.append(s)
00156   if withSortValue is _notPassed: withSortValue = withValue
00157   return l, withSortValue
def AdvancedQuery.sorting.sort (   seq,
  sortSpecs,
  withSortValue 
)
sort 'IISet/IITreeSet' *seq* according to *sortSpec*.

*sortSpecs* is a sequence of sort specs.

The result has '__getitem__' and '__len__' methods.
'__getitem__' must be called with sucessive integers, starting
with '0'. This is sufficient for 'LazyMap'.

If *withSortValue*, '__getitem__' returns triple
*sortValue*, 'None', *documentId*, otherwise *documentId*.

Definition at line 10 of file sorting.py.

00010 
00011 def sort(seq, sortSpecs, withSortValue):
00012   '''sort 'IISet/IITreeSet' *seq* according to *sortSpec*.
00013 
00014   *sortSpecs* is a sequence of sort specs.
00015 
00016   The result has '__getitem__' and '__len__' methods.
00017   '__getitem__' must be called with sucessive integers, starting
00018   with '0'. This is sufficient for 'LazyMap'.
00019 
00020   If *withSortValue*, '__getitem__' returns triple
00021   *sortValue*, 'None', *documentId*, otherwise *documentId*.
00022   '''
00023   n = len(seq)
00024   if not withSortValue and (not sortSpecs or n <= 1): return seq
00025   return _SortAccess(n, _sort(seq, sortSpecs, withSortValue))
00026 

Here is the call graph for this function:

Here is the caller graph for this function: