Ejemplo n.º 1
0
def search():
    table = db.movie
    doc = []
    for s in table.find({}, {"_id": False, "production_companies": True}):
        for t in s["production_companies"]:
            doc.append(t)
    doc = Counter(doc)
    print(type(doc))
    return makeResponse({"result": doc})
Ejemplo n.º 2
0
def searchbyCharacter():
    table = db.moviesnewfinal
    body = json.loads(request.data)
    condition = {"name": {"$regex": '^' + body['query'], '$options': 'i'}}
    doc = []
    if "filter" not in body or len(body["filter"]) == 0:
        for s in table.find(condition, {"_id": False}).limit(10):
            doc.append(s)

    else:
        for s in table.find(condition, check(body['filter'])).limit(10):
            doc.append(s)
    return makeResponse(doc)
Ejemplo n.º 3
0
def searchbyQuery():
    table = db.moviesnewfinal
    body = json.loads(request.data)
    print(body['query'])
    doc = []
    for s in table.find({
            body['field']: {
            "$regex": body['query']
        }
    }, {
            "_id": False
    }).limit(10):
        doc.append(s)
    return makeResponse(doc)
Ejemplo n.º 4
0
def searchbyQuery():
    table = db.movie
    body = json.loads(request.data.decode('utf-8'))
    print(body['query'])
    doc = []
    for s in table.find(
        {
            body['field']: {
                "$regex": body["query"],
                "$options": "i"
            }
        }, {
            "_id": False
        }).limit(12):
        doc.append(s)
    return makeResponse({"result": doc})
Ejemplo n.º 5
0
def searchbyPage():
    table = db.movie
    body = json.loads(request.data.decode('utf-8'))
    doc = []
    p = body['page']
    l = body['limit']
    totalData = table.count()
    if p * l > totalData or p == 0:
        doc.append({"result": "page is not present"})

    elif "filter" not in body or len(body["filter"]) == 0:
        for s in table.find({}, {"_id": False}).limit(l).skip(l * (p - 1)):
            doc.append(s)
    else:
        for s in table.find({},
                            check(body['filter'])).limit(l).skip(l * (p - 1)):
            doc.append(s)

    return makeResponse(doc)
Ejemplo n.º 6
0
def searchbyPageGenres():
    table = db.moviesnewfinal
    body = json.loads(request.data)
    p = body['page']
    l = body['limit']

    condition = {body['field']: {"$regex": body['query']}}
    doc = []
    if p * l > totalData or p == 0:
        doc.append({"result": "page is not present"})

    elif "filter" not in body or len(body["filter"]) == 0:
        for s in table.find(condition, {
                "_id": False
        }).limit(l).skip(l * (p - 1)):
            doc.append(s)
    else:
        if len(body["filter"]) > 0:
            for s in table.find(condition, check(
                    body['filter'])).limit(l).skip(l * (p - 1)):
                doc.append(s)

    return makeResponse(doc)
Ejemplo n.º 7
0
def production_companies():
    with open("./data/production_companies.json", "r") as f:
        content = json.load(f)
    return makeResponse(content)
Ejemplo n.º 8
0
def genres():
    with open("./data/genres.json", "r") as f:
        content = json.load(f)
    return makeResponse(content)
Ejemplo n.º 9
0
def searchbyId():
    body = json.loads(request.data)
    doc = db.movie.find_one({"id": body['id']}, {"_id": False})
    return makeResponse({"result": doc})