def limit(value): """ Limits the amount of documents found. .. code-block:: python uv.docs.find(D.limit(50)) """ if not type(value) is int: raise ValueError, "Limit predicates must be integers: limit(5)" return P.udf(Document.__lim__, count=value)
def skip(value): """ Skips the first few documents found based on the given input. .. code-block:: python # skips 50 records uv.docs.find(D.skip(50)) """ if not type(value) is int: raise ValueError, "Skip predicates must be integers: K.skip(5)" return P.udf(Document.__skip__, value)
def limskip(_skip, _limit): """ Skips the first few documents found and also limits the records found based on the given input. .. code-block:: python # skips 50 records and returns the next 50 uv.docs.find(D.limskip(50, 50)) """ if not type(_skip) is int: raise ValueError, "Skip argument must be an integer: K.limskip(2, 5)" if not type(_limit) is int: raise ValueError, "Limit argument must be an integer: K.limskip(2, 5)" return P.udf(Document.__limskip__, _skip, _limit)
def udf(function, *args, **kwargs): """ Passes the entire data stream to the user defined function along with any *args* and *kwargs*. This can be used to filter documents on multiple attributes of the data along with other advanced functionality. .. note:: The UDF takes the entire collection and returns a subset of documents matching complex criterion. This differs from the UDP functionality in the the UDP only receives a single attribute of one document at a time. .. code-block:: python def complex_filter(array): subset = [] for doc in array: if some_ninja_math: subset.append(doc) return subset uv.docs.find(D.udf(complex_filter)) Or a real example... .. code-block:: python # finds all docs where x**y > 4 def sq_filter(array, goal=2): subset = [] for doc in array: if doc.x ** doc.y > goal: subset.append(doc) return subset for d in verse.find(Document.udf(sq_filter, 4)): print d """ return P.udf(function, *args, **kwargs)