示例#1
0
def authors_index(start):
    q = model.Author.query
    q = q.filter(
        func.unaccent(model.Author.last_name +
                      ', ' + model.Author.first_name).ilike(
                          func.unaccent(start + '%'))).order_by(
                              model.Author.last_name, model.Author.first_name)
    return run_query_limited(q)
示例#2
0
def shelves_index(start, user):
    q = model.Bookshelf.query
    if user:
        q=q.filter(model.Bookshelf.created_by == user)
    else:
        q=q.filter(model.Bookshelf.public == True, model.Bookshelf.created_by != user)
    q = q.filter(func.unaccent(model.Bookshelf.name).ilike(
        func.unaccent(start + '%'))).order_by(model.Bookshelf.name)
    return run_query_limited(q)
示例#3
0
def series_index(start):
    # Need to add authors
    # select distinct series.*, author.id as author_id, author.first_name,
    # author.last_name from series left join ebook on series.id =
    # ebook.series_id join ebook_authors on ebook_authors.ebook_id=ebook.id
    # join author on author.id = ebook_authors.author_id;

    q = model.Series.query
    q = q.filter(func.unaccent(model.Series.title).ilike(
        func.unaccent(start + '%'))).order_by(model.Series.title)
    return run_query_limited(q)
示例#4
0
def shelves_index(start, user):
    q = model.Bookshelf.query
    if user:
        q = q.filter(model.Bookshelf.created_by == user)
    else:
        q = q.filter(model.Bookshelf.public == True,
                     model.Bookshelf.created_by != user)
    q = q.filter(
        func.unaccent(model.Bookshelf.name).ilike(
            func.unaccent(start + '%'))).order_by(model.Bookshelf.name)
    return run_query_limited(q)
示例#5
0
def series_index(start):
    # Need to add authors
    # select distinct series.*, author.id as author_id, author.first_name,
    # author.last_name from series left join ebook on series.id =
    # ebook.series_id join ebook_authors on ebook_authors.ebook_id=ebook.id
    # join author on author.id = ebook_authors.author_id;

    q = model.Series.query
    q = q.filter(
        func.unaccent(model.Series.title).ilike(
            func.unaccent(start + '%'))).order_by(model.Series.title)
    return run_query_limited(q)
示例#6
0
def find_area():
    """

    :return:
    """
    try:
        search_name = "%{}%".format(request.args.get("q"))
        search_code = request.args.get("q")
        qarea = (DB.session.query(
            MVLAreasAutocomplete.id,
            MVLAreasAutocomplete.type_name,
            MVLAreasAutocomplete.type_desc,
            MVLAreasAutocomplete.type_code,
            MVLAreasAutocomplete.area_name,
            MVLAreasAutocomplete.area_code,
        ).filter(
            or_(
                MVLAreasAutocomplete.search_area_name.like(
                    func.unaccent(search_name.lower())),
                MVLAreasAutocomplete.area_code == search_code,
            )).limit(20))
        print(qarea)
        result = qarea.all()
        count = len(result)
        datas = []
        for r in result:
            datas.append(r._asdict())
        return {"count": count, "datas": datas}, 200

    except Exception as e:
        current_app.logger.error("<find_area> ERROR:", e)
        return {"Error": str(e)}, 400
示例#7
0
def filter_shelves(q, filter):
    return q.filter(func.unaccent(model.Bookshelf.name).ilike(func.unaccent(text("'%%%s%%'" % filter))))
示例#8
0
def filter_ebooks(q, filter):
    return q.filter(func.unaccent(model.Ebook.title).ilike(func.unaccent(text("'%%%s%%'" % filter))))
示例#9
0
def authors_index(start):
    q = model.Author.query
    q = q.filter(func.unaccent(model.Author.last_name + ', ' + model.Author.first_name)
                 .ilike(func.unaccent(start + '%'))).order_by(model.Author.last_name, model.Author.first_name)
    return run_query_limited(q)
示例#10
0
def ebooks_index(start):
    q = model.Ebook.query
    q = q.filter(func.unaccent(model.Ebook.title).ilike(
        func.unaccent(start + '%'))).order_by(model.Ebook.title)
    return run_query_limited(q)
示例#11
0
def filter_shelves(q, filter):
    return q.filter(
        func.unaccent(model.Bookshelf.name).ilike(
            func.unaccent(text("'%%%s%%'" % filter))))
示例#12
0
def filter_ebooks(q, filter):
    return q.filter(
        func.unaccent(model.Ebook.title).ilike(
            func.unaccent(text("'%%%s%%'" % filter))))
示例#13
0
def ebooks_index(start):
    q = model.Ebook.query
    q = q.filter(
        func.unaccent(model.Ebook.title).ilike(
            func.unaccent(start + '%'))).order_by(model.Ebook.title)
    return run_query_limited(q)
示例#14
0
def _similarity(query, text):
    return func.word_similarity(func.unaccent(query), func.unaccent(text))
示例#15
0
def _similarity(statement, text):
    return func.word_similarity(func.unaccent(statement), func.unaccent(text))
示例#16
0
def series_index(start):
    q = model.Series.query
    q = q.filter(func.unaccent(model.Series.title).ilike(
        func.unaccent(start + '%'))).order_by(model.Series.title)
    return _run_query(q)