Logo Search packages:      
Sourcecode: zope-advancedquery version File versions  Download package

def AdvancedQuery::sorting::IndexSorter::group (   self,
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.

    sortIndex = self._sortIndex; sortReverse = self._sortReverse
    ns = len(seq); ni = len(sortIndex)
    if ns >= 0.1 * ni:
      # result large compared to index -- sort via index
      handled = IISet(); hn = 0
      _load = getattr(sortIndex, '_load', None)
      if _load is None:
        # not an optimized index
        items = sortIndex.items()
        _load = lambda (x1, x2): x2
        if sortReverse: items.reverse()
      elif sortReverse:
        gRO = getattr(sortIndex, 'getReverseOrder', None)
        items = gRO and gRO()
        if items is None:
          items = list(sortIndex._index.keys()); items.reverse()
      else: items = sortIndex._index.keys()
      for i in items:
        ids = intersection(seq, _load(i))
        if ids:
          handled.update(ids); hn += len(ids)
          yield i, ids
      if hn != len(seq): yield None, difference(seq, handled)
      # result relatively small -- sort via result
      keyFor = sortIndex.keyForDocument; m = OOBTree()
      noValue = IITreeSet()
      for doc in seq.keys():
        try: k = keyFor(doc)
        except KeyError: noValue.insert(doc); continue
        l = m.get(k)
        if l is None: l = m[k] = IITreeSet()
      items = m.items()
      if sortReverse: items = list(items); items.reverse()
      for i in items: yield i
      if noValue: yield None, noValue

Generated by  Doxygen 1.6.0   Back to index