Esempio n. 1
0
def render_homepage():
    is_search = False
    search = Movie.search()
    query = request.args.get('search', None)
    genre = request.args.get('genre', [])
    min_rate = request.args.get('min-rate', '')
    max_rate = request.args.get('max-rate', '')
    if request.args:
        is_search = True
        q = Q('bool',
              must=[Q('match', title=query)],
              should=[Q('match', summary=query)])
        search = search.query("match", q)
        print(query, genre, min_rate, max_rate)
        search = search.filter('terms', genre=genre)

    results = search.execute()
    all_genre = get_all_genre()
    return render_template('homepage/home.html',
                           movies=results,
                           genres=all_genre,
                           is_search=is_search)
Esempio n. 2
0
from elasticsearch_dsl import A
from app.models.movie import Movie
from pprint import pprint

search = Movie.search()


def get_all_genre():
    genre_agg = A('terms', field='genre.raw')
    search.aggs.bucket('genre_terms', genre_agg)
    result = search.execute()
    # pprint(result.aggregations['genre_terms']['buckets'])
    return result.aggregations['genre_terms']['buckets']