Back to index

plone3  3.1.7
Public Member Functions | Private Attributes
AdvancedQuery.sorting.IndexSorter Class Reference
Inheritance diagram for AdvancedQuery.sorting.IndexSorter:
Inheritance graph
[legend]
Collaboration diagram for AdvancedQuery.sorting.IndexSorter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def group

Private Attributes

 _sortIndex
 _sortReverse

Detailed Description

sorting with respect to an index.

Definition at line 83 of file sorting.py.


Constructor & Destructor Documentation

def AdvancedQuery.sorting.IndexSorter.__init__ (   self,
  sortIndex,
  sortReverse 
)

Definition at line 85 of file sorting.py.

00085 
00086   def __init__(self, sortIndex, sortReverse):
00087     self._sortIndex = sortIndex; self._sortReverse = sortReverse

Here is the caller graph for this function:


Member Function Documentation

def AdvancedQuery.sorting.IndexSorter.group (   self,
  seq 
)
group *seq* (a set) generating pairs (*value*, *subseq*).

All elements in *subseq* (a set) have *value* as sort value on this level.
The union of all *subseq* gives *seq*.

Elements not sorted on this level go into the last generated
pair with 'None' as value.

Reimplemented from AdvancedQuery.sorting.Sorter.

Definition at line 88 of file sorting.py.

00088 
00089   def group(self, seq):
00090     sortIndex = self._sortIndex; sortReverse = self._sortReverse
00091     ns = len(seq); ni = len(sortIndex)
00092     if ns >= 0.1 * ni:
00093       # result large compared to index -- sort via index
00094       handled = IISet(); hn = 0
00095       _load = getattr(sortIndex, '_load', None)
00096       if _load is None:
00097         # not an optimized index
00098         items = sortIndex.items()
00099         
00100         _load = lambda (x1, x2): x2
00101         if sortReverse: items.reverse()
00102       elif sortReverse:
00103         gRO = getattr(sortIndex, 'getReverseOrder', None)
00104         items = gRO and gRO()
00105         if items is None:
00106           items = list(sortIndex._index.keys()); items.reverse()
00107       else: items = sortIndex._index.keys()
00108       for i in items:
00109         ids = intersection(seq, _load(i))
00110         if ids:
00111           handled.update(ids); hn += len(ids)
00112           yield i, ids
00113       if hn != len(seq): yield None, difference(seq, handled)
00114     else:
00115       # result relatively small -- sort via result
00116       keyFor = sortIndex.keyForDocument; m = OOBTree()
00117       noValue = IITreeSet()
00118       for doc in seq.keys():
00119         try: k = keyFor(doc)
00120         except KeyError: noValue.insert(doc); continue
00121         l = m.get(k)
00122         if l is None: l = m[k] = IITreeSet()
00123         l.insert(doc)
00124       items = m.items()
00125       if sortReverse: items = list(items); items.reverse()
00126       for i in items: yield i
00127       if noValue: yield None, noValue
00128 


Member Data Documentation

Definition at line 86 of file sorting.py.

Definition at line 86 of file sorting.py.


The documentation for this class was generated from the following file: