Example #1
0
def search():

    formsearch = RecipeSearchForm()
    form = PostFormHungryFor()
    formNormalText = PostForm()
    formCurrent = PostFormCurrentlyEating()

    if request.method == 'POST':

        minmax = request.form['minmax']
        minmax = minmax.replace('-', '')
        minmax = minmax.replace('$', '').split()

        calories = request.form['calories']
        calories = calories.replace('-', '')
        calories = calories.replace('$', '').split()

    if formsearch.validate_on_submit():
        if is_filled(formsearch.keyWord.data):
            keywords = parser_first_round(formsearch.keyWord.data)
            keywords_sufix = parser_search_sufix(formsearch.keyWord.data)
            print(keywords_sufix)

            print(keywords)

            recipes = db.engine.execute("SELECT * FROM (SELECT * FROM rec WHERE (minPrice <= %s AND maxprice >= %s) AND ( calories >= %s AND calories <= %s ) AND \
                ((MATCH (rec_name, rec_description, rec_instruction, ings, tags) \
                    AGAINST (%s IN BOOLEAN MODE)))) as b left join (select id as useridd, username from users) as a on b.user_id = a.useridd \
                    UNION \
                    SELECT * FROM (SELECT * FROM rec where rec_name LIKE %s)  as b left join (select id as useridd, username from users) as a on b.user_id = a.useridd  \
                    ", minmax[1], minmax[0], calories[0], calories[1], keywords, keywords_sufix )


            return render_template('homepage.html', form5=formsearch, form=form, form2=formNormalText, form3=formCurrent, recipes=recipes)



        else:

            recipes = db.engine.execute("SELECT * FROM rec WHERE (minPrice <= %s AND maxprice >= %s) AND ( calories >= %s AND calories <= %s )", minmax[1], minmax[0], calories[0], calories[1])
            return render_template('homepage.html', form5=formsearch, form=form, form2=formNormalText, form3=formCurrent, recipes=recipes)

    return render_template('homepage.html', form5=formsearch, form=form, form2=formNormalText, form3=formCurrent)
Example #2
0
def advancedsearch():
    formsearch = RecipeSearchForm()
    print(formsearch.keyWord.data)
    if formsearch.validate_on_submit():
        print(formsearch.keyWord.data)
    return render_template("advancedsearchpage.html", form5=formsearch)