def filter2query(filter):
    """
    http://docs.mongodb.org/manual/reference/operator/query/
    """
    query = {}
    filter = filter or {}
    for k, v in filter.items():
        if isinstance(v, tuple):
            operator, v = v
            mop = '$%s' % operator
            value = {mop: v}
        elif isinstance(v, list):
            value = {'$in': v}
        else:
            value = v
        query[k] = value
    """
    if keyword:
        #filter = {'description':{"$regex": keyword}}
        mongokeywordfilter = {"$or": [
            {"description": {"$regex": keyword,'$options':'i'}},
            {"title": {"$regex": keyword,'$options':'i'}}
        ]}
        query = {
            "$and": [ query, mongokeywordfilter ]
        }
    """
    return query
