Back to index

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

List of all members.

Public Member Functions

def group

Private Member Functions

def _group

Detailed Description

a sorter corresponding to 'RankByQueries_Sum'.

Definition at line 65 of file ranking.py.


Member Function Documentation

def AdvancedQuery.ranking._RankerByQueries_Sum._group (   self,
  seq 
) [private]

Reimplemented from AdvancedQuery.ranking._Ranker.

Definition at line 67 of file ranking.py.

00067 
00068   def _group(self, seq):
00069     spec = self._spec; cat = self._cat
00070     mv = spec.getQueryValueSum(); vqs = spec._getValueQuerySequence()
00071     def generate(seq, vqs, mv):
00072       if not vqs: yield 0, seq; return
00073       vqs = vqs[:] # avoid side effects
00074       v,q = vqs.pop(); mv -= v
00075       q = And(LiteralResultSet(seq), q)
00076       qr = _eval(q, cat)
00077       if qr:
00078         feed1 = generate(qr, vqs, mv)
00079         seq = difference(seq, qr)
00080       else: feed1 = None
00081       feed2 = seq and generate(seq, vqs, mv) or None
00082       def fetch1():
00083         if feed1 is None: return None
00084         try: val, subseq = feed1.next(); return val + v, subseq
00085         except StopIteration: return None
00086       def fetch2():
00087         if feed2 is None: return None
00088         try: return feed2.next()
00089         except StopIteration: return None
00090       g1 = fetch1()
00091       # largest value from "feed1" only
00092       while g1 is not None and g1[0] > mv: yield g1; g1 = fetch1()
00093       # merge largest values from "feed1" and "feed2"
00094       g2 = fetch2()
00095       while g1 is not None and g2 is not None:
00096         v1 = g1[0]; v2 = g2[0]
00097         if v1 > v2: yield g1; g1 = fetch1()
00098         elif v2 > v1: yield g2; g2 = fetch2()
00099         # Note: g1[1] was copied (by the "intersection" above); therfore,
00100         #  we can destructively change it
00101         else: g1[1].update(g2[1]); yield g1; g1 = fetch1(); g2 = fetch2()
00102       # handle feed1
00103       while g1 is not None: yield g1; g1 = fetch1()
00104       # handle feed2
00105       while g2 is not None: yield g2; g2 = fetch2()
00106     for g in generate(seq, vqs, mv): yield g
00107 

Here is the call graph for this function:

def AdvancedQuery.ranking._Ranker.group (   self,
  seq 
) [inherited]

Definition at line 23 of file ranking.py.

00023 
00024   def group(self, seq):
00025     normalize = self._normalize
00026     for rank, subseq in self._group(seq):
00027       yield normalize(rank), subseq

Here is the call graph for this function:


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