selectors.py
changeset 5944 b962dff47c36
parent 5904 6371b6760dc9
child 6008 e1c43115af3b
equal deleted inserted replaced
5943:f1abba8ccc01 5944:b962dff47c36
   200 from logilab.common.deprecation import class_renamed
   200 from logilab.common.deprecation import class_renamed
   201 from logilab.common.compat import all, any
   201 from logilab.common.compat import all, any
   202 from logilab.common.interface import implements as implements_iface
   202 from logilab.common.interface import implements as implements_iface
   203 
   203 
   204 from yams import BASE_TYPES
   204 from yams import BASE_TYPES
       
   205 from rql.nodes import Function
   205 
   206 
   206 from cubicweb import (Unauthorized, NoSelectableObject, NotAnEntity,
   207 from cubicweb import (Unauthorized, NoSelectableObject, NotAnEntity,
   207                       CW_EVENT_MANAGER, role)
   208                       CW_EVENT_MANAGER, role)
   208 # even if not used, let yes here so it's importable through this module
   209 # even if not used, let yes here so it's importable through this module
   209 from cubicweb.appobject import Selector, objectify_selector, lltrace, yes
   210 from cubicweb.appobject import Selector, objectify_selector, lltrace, yes
   586 
   587 
   587 @objectify_selector
   588 @objectify_selector
   588 @lltrace
   589 @lltrace
   589 def sorted_rset(cls, req, rset=None, **kwargs):
   590 def sorted_rset(cls, req, rset=None, **kwargs):
   590     """Return 1 for sorted result set (e.g. from an RQL query containing an
   591     """Return 1 for sorted result set (e.g. from an RQL query containing an
   591     :ref:ORDERBY clause.
   592     :ref:ORDERBY clause), with exception that it will return 0 if the rset is
       
   593     'ORDERBY FTIRANK(VAR)' (eg sorted by rank value of the has_text index).
   592     """
   594     """
   593     if rset is None:
   595     if rset is None:
   594         return 0
   596         return 0
   595     rqlst = rset.syntax_tree()
   597     selects = rset.syntax_tree().children
   596     if len(rqlst.children) > 1 or not rqlst.children[0].orderby:
   598     if (len(selects) > 1 or
       
   599         not selects[0].orderby or
       
   600         (isinstance(selects[0].orderby[0].term, Function) and
       
   601          selects[0].orderby[0].term.name == 'FTIRANK')
       
   602         ):
   597         return 0
   603         return 0
   598     return 2
   604     return 2
   599 
   605 
   600 
   606 
   601 # XXX == multi_etypes_rset(1)
   607 # XXX == multi_etypes_rset(1)