1105 |
1105 |
1106 _EXT_REGISTERED = False |
1106 _EXT_REGISTERED = False |
1107 def register_stored_procedures(): |
1107 def register_stored_procedures(): |
1108 from logilab.database import FunctionDescr |
1108 from logilab.database import FunctionDescr |
1109 from rql.utils import register_function, iter_funcnode_variables |
1109 from rql.utils import register_function, iter_funcnode_variables |
|
1110 from rql.nodes import SortTerm, Constant, VariableRef |
1110 |
1111 |
1111 global _EXT_REGISTERED |
1112 global _EXT_REGISTERED |
1112 if _EXT_REGISTERED: |
1113 if _EXT_REGISTERED: |
1113 return |
1114 return |
1114 _EXT_REGISTERED = True |
1115 _EXT_REGISTERED = True |
1148 |
1149 |
1149 class TEXT_LIMIT_SIZE(LIMIT_SIZE): |
1150 class TEXT_LIMIT_SIZE(LIMIT_SIZE): |
1150 supported_backends = ('mysql', 'postgres', 'sqlite',) |
1151 supported_backends = ('mysql', 'postgres', 'sqlite',) |
1151 |
1152 |
1152 register_function(TEXT_LIMIT_SIZE) |
1153 register_function(TEXT_LIMIT_SIZE) |
|
1154 |
|
1155 |
|
1156 class FTIRANK(FunctionDescr): |
|
1157 """return ranking of a variable that must be used as some has_text |
|
1158 relation subject in the query's restriction. Usually used to sort result |
|
1159 of full-text search by ranking. |
|
1160 """ |
|
1161 supported_backends = ('postgres',) |
|
1162 rtype = 'Float' |
|
1163 |
|
1164 def st_check_backend(self, backend, funcnode): |
|
1165 """overriden so that on backend not supporting fti ranking, the |
|
1166 function is removed when in an orderby clause, or replaced by a 1.0 |
|
1167 constant. |
|
1168 """ |
|
1169 if not self.supports(backend): |
|
1170 parent = funcnode.parent |
|
1171 while parent is not None and not isinstance(parent, SortTerm): |
|
1172 parent = parent.parent |
|
1173 if isinstance(parent, SortTerm): |
|
1174 parent.parent.remove(parent) |
|
1175 else: |
|
1176 funcnode.parent.replace(funcnode, Constant(1.0, 'Float')) |
|
1177 parent = funcnode |
|
1178 for vref in parent.iget_nodes(VariableRef): |
|
1179 vref.unregister_reference() |
|
1180 |
|
1181 register_function(FTIRANK) |
1153 |
1182 |
1154 |
1183 |
1155 class FSPATH(FunctionDescr): |
1184 class FSPATH(FunctionDescr): |
1156 """return path of some bytes attribute stored using the Bytes |
1185 """return path of some bytes attribute stored using the Bytes |
1157 File-System Storage (bfss) |
1186 File-System Storage (bfss) |