def _add_zfilters(self): k, v = self._zfilters[0].items()[0] try: att, op = k.split('__') except ValueError: raise ValueError("zfilter should have an operator.") index = self.model_class._key[att] desc = self.model_class._attributes[att] zset = SortedSet(index) limit, offset = self._get_limit_and_offset() if isinstance(v, (tuple, list,)): min, max = v min = float(desc.typecast_for_storage(min)) max = float(desc.typecast_for_storage(max)) else: v = float(desc.typecast_for_storage(v)) if op == 'lt': return zset.lt(v, limit, offset) elif op == 'gt': return zset.gt(v, limit, offset) elif op == 'gte': return zset.ge(v, limit, offset) elif op == 'lte': return zset.le(v, limit, offset) elif op == 'in': return zset.between(min, max, limit, offset)
def _add_zfilters(self): """ This function is the internals of the zfilter function. It will create a SortedSet and will compare the scores to the value provided. :return: a SortedSet with the ids. """ k, v = self._zfilters[0].items()[0] try: att, op = k.split('__') except ValueError: raise ValueError("zfilter should have an operator.") index = self.model_class._key[att] desc = self.model_class._attributes[att] zset = SortedSet(index, db=self.db) limit, offset = self._get_limit_and_offset() if isinstance(v, (tuple, list,)): min, max = v min = float(desc.typecast_for_storage(min)) max = float(desc.typecast_for_storage(max)) else: v = float(desc.typecast_for_storage(v)) if op == 'lt': return zset.lt(v, limit, offset) elif op == 'gt': return zset.gt(v, limit, offset) elif op == 'gte': return zset.ge(v, limit, offset) elif op == 'lte': return zset.le(v, limit, offset) elif op == 'in': return zset.between(min, max, limit, offset)
def _add_zfilters(self): k, v = self._zfilters[0].items()[0] try: att, op = k.split('__') except ValueError: raise ValueError("zfilter should have an operator.") index = self.model_class._key[att] desc = self.model_class._attributes[att] zset = SortedSet(index) limit, offset = self._get_limit_and_offset() if isinstance(v, ( tuple, list, )): min, max = v min = float(desc.typecast_for_storage(min)) max = float(desc.typecast_for_storage(max)) else: v = float(desc.typecast_for_storage(v)) if op == 'lt': return zset.lt(v, limit, offset) elif op == 'gt': return zset.gt(v, limit, offset) elif op == 'gte': return zset.ge(v, limit, offset) elif op == 'lte': return zset.le(v, limit, offset) elif op == 'in': return zset.between(min, max, limit, offset)
def _add_zfilters(self, s): """ This function is the internals of the zfilter function. It will create a SortedSet and will compare the scores to the value provided. :return: a SortedSet with the ids. """ k, v = self._zfilters[0].items()[0] try: att, op = k.split('__') except ValueError: raise ValueError("zfilter should have an operator.") index = self.model_class._key[att] desc = self.model_class._attributes[att] zset = SortedSet(index, db=self.db) limit, offset = self._get_limit_and_offset() new_set_key = "~%s.%s" % ("+".join([self.key, att, op]), id(self)) new_set_key_temp = "#%s.%s" % ("+".join([self.key, att, op]), id(self)) members = [] if isinstance(v, ( tuple, list, )): min, max = v min = float(desc.typecast_for_storage(min)) max = float(desc.typecast_for_storage(max)) else: v = float(desc.typecast_for_storage(v)) if op == 'lt': members = zset.lt(v, limit, offset) elif op == 'gt': members = zset.gt(v, limit, offset) elif op == 'gte': members = zset.ge(v, limit, offset) elif op == 'le': members = zset.le(v, limit, offset) elif op == 'lte': members = zset.le(v, limit, offset) elif op == 'in': members = zset.between(min, max, limit, offset) temp_set = Set(new_set_key_temp) if members: temp_set.add(*members) temp_set.set_expire() s.intersection(new_set_key, temp_set) new_set = Set(new_set_key) new_set.set_expire() return new_set
def _add_zfilters(self, s): """ This function is the internals of the zfilter function. It will create a SortedSet and will compare the scores to the value provided. :return: a SortedSet with the ids. """ k, v = self._zfilters[0].items()[0] try: att, op = k.split('__') except ValueError: raise ValueError("zfilter should have an operator.") index = self.model_class._key[att] desc = self.model_class._attributes[att] zset = SortedSet(index, db=self.db) limit, offset = self._get_limit_and_offset() new_set_key = "~%s.%s" % ("+".join([self.key, att, op]), id(self)) new_set_key_temp = "#%s.%s" % ("+".join([self.key, att, op]), id(self)) members = [] if isinstance(v, (tuple, list,)): min, max = v min = float(desc.typecast_for_storage(min)) max = float(desc.typecast_for_storage(max)) else: v = float(desc.typecast_for_storage(v)) if op == 'lt': members = zset.lt(v, limit, offset) elif op == 'gt': members = zset.gt(v, limit, offset) elif op == 'gte': members = zset.ge(v, limit, offset) elif op == 'le': members = zset.le(v, limit, offset) elif op == 'lte': members = zset.le(v, limit, offset) elif op == 'in': members = zset.between(min, max, limit, offset) temp_set = Set(new_set_key_temp) if members: temp_set.add(*members) temp_set.set_expire() s.intersection(new_set_key, temp_set) new_set = Set(new_set_key) new_set.set_expire() return new_set