Exemplo n.º 1
0
def search():
    '''
    Gestiona las URL de busqueda de archivos para la aplicacion.
    '''
    query = request.form.get("q", None)
    filetype = request.form.get("t", None)

    if query:  #si no se ha buscado nada se manda al inicio
        query = query.replace(
            "_",
            " ")  #para que funcionen la busqueda cuando vienen varias palabras

    filters = {"src": "torrent"}

    ori_query = query

    _in = [i for i, v in enumerate(g.categories) if v[0] == filetype]
    if filetype and _in:
        _id = _in[0]
        if "t" in g.categories[_id][1]:
            filters["type"] = g.categories[_id][1]['t']
        if "q" in g.categories[_id][1]:
            _type = g.categories[_id][1]['q']
            query = "%s (%s)" % (query, _type)

    args = filters.copy()
    args["q"] = ori_query
    if ori_query != query:
        args['type'] = _type
    g.args = args

    sure = False
    total_found = 0

    if query:
        search_results = search_files(
            query,
            filters,
            min_results=50,
            last_items=[],
            non_group=True,
            order=("@weight*(r+10)",
                   "e DESC, ok DESC, r2 DESC, fs DESC, uri1 DESC",
                   "@weight*(r+10)"),
            weight_processor=weight_processor,
            tree_visitor=tree_visitor)
    else:
        search_results = {"last_items": [], "files": [], "result_number": ""}

    #~ for result in search_results:

    return render_template(
        'search.html',
        query=ori_query,
        filetype=filetype,
        last_items=search_results["last_items"],
        files=[torrents_data(afile) for afile in search_results["files"]],
        result_number=search_results["result_number"].replace(
            query, ori_query))
Exemplo n.º 2
0
def searcha():
    '''
    Responde las peticiones de busqueda por ajax
    '''

    query=request.form.get("query",None)
    filetype=request.form.get("filetype",None)

    if not query: #si no se ha buscado nada se manda al inicio
        logging.error("Invalid data for AJAX search request.")
        return jsonify({})

    query = query.replace("_"," ") if query is not None else None #para que funcionen la busqueda cuando vienen varias palabras
    filters = {"src":"torrent"}
    ori_query = query

    _in = [i for i, v in enumerate(g.categories) if v[0] == filetype]
    if filetype and _in :
        _id = _in[0]
        if "t" in g.categories[_id][1]:
            filters["type"] = g.categories[_id][1]['t']
        if "q" in g.categories[_id][1]:
            _type = g.categories[_id][1]['q']
            query = "%s (%s)" % (query, _type)

    args = filters.copy()
    args["q"] = ori_query
    if ori_query != query:
        args['type'] = _type
    g.args=args

    last_items = []
    try:
        last_items = b64decode(str(request.form["last_items"]) if "last_items" in request.form else "", "-_")
        if last_items:
            last_items = unpack("%dh"%(len(last_items)/2), last_items)
    except BaseException as e:
        logging.error("Error parsing last_items information from request.")

    sure = False
    total_found=0

    search_results = search_files(query, filters, min_results=0, last_items=last_items, non_group=True, order=("@weight*(r+10)", "e DESC, ok DESC, r2 DESC, fs DESC, uri1 DESC", "@weight*(r+10)"), weight_processor=weight_processor, tree_visitor=tree_visitor)

    response = make_response(render_template('file.html',files=[torrents_data(afile) for afile in search_results["files"]]))
    del search_results["files"]

    response.headers["X-JSON"]=json.dumps(search_results)
    return response
Exemplo n.º 3
0
def search():
    '''
    Gestiona las URL de busqueda de archivos para la aplicacion.
    '''
    query=request.form.get("q",None)
    filetype=request.form.get("t",None)

    if query: #si no se ha buscado nada se manda al inicio
        query = query.replace("_"," ")  #para que funcionen la busqueda cuando vienen varias palabras

    filters = {"src":"torrent"}

    ori_query = query

    _in = [i for i, v in enumerate(g.categories) if v[0] == filetype]
    if filetype and _in :
        _id = _in[0]
        if "t" in g.categories[_id][1]:
            filters["type"] = g.categories[_id][1]['t']
        if "q" in g.categories[_id][1]:
            _type = g.categories[_id][1]['q']
            query = "%s (%s)" % (query, _type)

    args = filters.copy()
    args["q"] = ori_query
    if ori_query != query:
        args['type'] = _type
    g.args=args

    sure = False
    total_found=0

    if query:
        search_results = search_files(query, filters, min_results=50, last_items=[], non_group=True, order=("@weight*(r+10)", "e DESC, ok DESC, r2 DESC, fs DESC, uri1 DESC", "@weight*(r+10)"), weight_processor=weight_processor, tree_visitor=tree_visitor)
    else:
        search_results = {"last_items":[], "files":[], "result_number":""}

    #~ for result in search_results:


    return render_template('search.html',
        query=ori_query, filetype=filetype, last_items=search_results["last_items"],
        files=[torrents_data(afile) for afile in search_results["files"]],
        result_number=search_results["result_number"].replace(query, ori_query)
    )
Exemplo n.º 4
0
def searcha():
    '''
    Responde las peticiones de busqueda por ajax
    '''

    query = request.form.get("query", None)
    filetype = request.form.get("filetype", None)

    if not query:  #si no se ha buscado nada se manda al inicio
        logging.error("Invalid data for AJAX search request.")
        return jsonify({})

    query = query.replace(
        "_", " "
    ) if query is not None else None  #para que funcionen la busqueda cuando vienen varias palabras
    filters = {"src": "torrent"}
    ori_query = query

    _in = [i for i, v in enumerate(g.categories) if v[0] == filetype]
    if filetype and _in:
        _id = _in[0]
        if "t" in g.categories[_id][1]:
            filters["type"] = g.categories[_id][1]['t']
        if "q" in g.categories[_id][1]:
            _type = g.categories[_id][1]['q']
            query = "%s (%s)" % (query, _type)

    args = filters.copy()
    args["q"] = ori_query
    if ori_query != query:
        args['type'] = _type
    g.args = args

    last_items = []
    try:
        last_items = b64decode(
            str(request.form["last_items"])
            if "last_items" in request.form else "", "-_")
        if last_items:
            last_items = unpack("%dh" % (len(last_items) / 2), last_items)
    except BaseException as e:
        logging.error("Error parsing last_items information from request.")

    sure = False
    total_found = 0

    search_results = search_files(
        query,
        filters,
        min_results=0,
        last_items=last_items,
        non_group=True,
        order=("@weight*(r+10)",
               "e DESC, ok DESC, r2 DESC, fs DESC, uri1 DESC",
               "@weight*(r+10)"),
        weight_processor=weight_processor,
        tree_visitor=tree_visitor)

    response = make_response(
        render_template(
            'file.html',
            files=[torrents_data(afile) for afile in search_results["files"]]))
    del search_results["files"]

    response.headers["X-JSON"] = json.dumps(search_results)
    return response