Esempio n. 1
0
    def _make_orfilter(self, filter, values):
        '''
        it creates an all fitler depending on the param and the list of values.
        site = [1,2,3]
        site in 1 or 2 or 3
        '''
        seperator = self.model.key_seperator
        key_index = self.model.key_order.index(filter) + 1
        tokenize_filter = key_filter.tokenize(seperator, key_index)

        for v in values:
            try:
                filters = filters | key_filter.eq(str(v))
            except NameError:
                filters = key_filter.eq(str(v))

        final = tokenize_filter + filters
        return final
Esempio n. 2
0
 def get_log_messages(self, items=10, level='INFO'):
     """Get log messages from Riak.
     """
     client = riak.RiakClient(self._host, self._port)
     query = client.add(self._bucket.get_name())
     filters = (key_filter.tokenize('-', 1) + key_filter.less_than(str(time.time()))) \
                 & (key_filter.tokenize('-', 2) + key_filter.eq(level))
     query.add_key_filters(filters)
     query.map_values_json()\
         .reduce_sort('function(a, b) { return b.created - a.created }')\
         .reduce_limit(items)
     for result in query.run():
         yield result