コード例 #1
0
def search_result():
    formq = SearchBar()
    if formq.validate_on_submit():
        text = formq.search_query.data
        print(text, type(text), bool(text == 'All'))
        if bool(text == 'All'):
            results = Hobies.query.all()
        else:
            search_query = w_tok(text)
            words = []
            for w in search_query:
                words.append('%' + w + '%')
            query_str = "SELECT * FROM hobies WHERE "
            query_str += "tag LIKE " + "'" + words[
                0] + "'" + " OR title LIKE " + "'" + words[
                    0] + "'" + " OR content LIKE " + "'" + words[0] + "'"
            for w in words[1:]:
                query_str += "OR tag LIKE " + "'" + w + "'" + " OR title LIKE " + "'" + w + "'" + " OR content LIKE " + "'" + w + "'"
            results = db.engine.execute(query_str)
            print("Search Executed")
            print(query_str)
        return render_template('search_result.html',
                               form=LoginForm(),
                               text=text,
                               forml=RegistrationForm(),
                               formq=formq,
                               hob=results,
                               title='Search_Result')
    return redirect(url_for('home'))
コード例 #2
0
ファイル: views.py プロジェクト: kpeng94/foodbook
def search_ingredients(request):
	if request.method == 'POST':
		form = SearchBar(request.POST)
		search = True
		if form.is_valid():
			manager = Ingredient.objects.filter(name__startswith=form.cleaned_data['searchbar']).order_by('name')
	else:
		form = SearchBar()
		search = False
		manager = Ingredient.objects.all()
	return render_to_response('search_ingredients.html', {'form': form, 'ingredient_list': manager, 'search': search}, context_instance=RequestContext(request))
コード例 #3
0
def home():
    formq = SearchBar()
    return render_template('home.html',
                           form=LoginForm(),
                           forml=RegistrationForm(),
                           formq=formq,
                           title='Home')
コード例 #4
0
ファイル: __init__.py プロジェクト: louis-126/app-deve
def retrieve_qns():
    search = SearchBar(request.form)
    if request.method == 'POST':
        db = shelve.open('faqstorage.db', 'r')
        qns_dict = db['FAQ']
        db.close()

        qns_list = []
        for key in qns_dict:
            question = qns_dict.get(key)
            if search.search.data.lower() in question.get_question().lower():
                qns_list.append(question)

        return render_template('retrieveQns.html',
                               count=len(qns_list),
                               qn_list=qns_list,
                               form=search)

    qn_dict = {}
    db = shelve.open('faqstorage.db', 'r')
    qn_dict = db['FAQ']
    db.close()

    qn_list = []
    for key in qn_dict:
        question = qn_dict.get(key)
        qn_list.append(question)

    return render_template('retrieveQns.html',
                           count=len(qn_list),
                           qn_list=qn_list,
                           form=search)
コード例 #5
0
def recipe(_id):
    search_form = SearchBar()
    recipe_id = request.form['recipe_id']
    processed_query = request.form['processed_query']
    query_list = processed_query.split(' ')
    engine.update_clickthrough(query_keywords=query_list, _id=recipe_id, clickthrough=engine.clickthrough)
    return render_template('recipe.html', _id=_id, recipe=recipeData[str(_id)], form=search_form)
コード例 #6
0
def store(**kwargs):

    search_form = SearchBar() # Searchbar HTML form


    if request.method =='POST':
        if search_form.validate_on_submit():
            search_query = search_form.query.data
            if request.args.get('page') == None:
                skip_num = 0
            else:
                skip_num = int(request.args.get('page'))*36
            return get_products.search_product(search_query, search_form, skip_num)


    # try:
    #     current_page = int(request.args['page_num'])
    #     skip_num = (current_page-1)*PRODUCT_LIMIT
    #
    # except:
    #     skip_num = 0 # products to skip

    elif kwargs.get('query') != None:
        if request.args.get('page') == None:
            skip_num = 0
        else:
            skip_num = int(request.args.get('page'))*36
        products = get_products.get_by_category(query=kwargs.get('query'), skip_num=skip_num)

    else:
        print('hi')
        if request.args.get('page') == None:
            skip_num = 0
        else:
            skip_num = int(request.args.get('page'))*36

        products = get_products.all_products(skip_num=skip_num)


    page = request.args.get(get_page_parameter(), type=int, default=1)
    pagination = Pagination(show_single_page= True,page=page, per_page=37, total=int(products.total), search=False, record_name='products')
    # pages = ceil(products.total/PRODUCT_LIMIT) # Total Number of pages

    return render_template('store.html', products=products, search_form=search_form, pagination=pagination)
コード例 #7
0
def home():
    form = SearchBar()
    posts = Articles.query.all()
    articles_list = Articles.query.order_by(
        Articles.popularity.desc()).limit(5)
    articles_list1 = Articles.query.order_by(
        Articles.date_posted.desc()).limit(5)
    return render_template('home.html',
                           title='home',
                           posts=posts,
                           form=form,
                           articles=articles_list,
                           art=articles_list1)
コード例 #8
0
def results():
    search_form = SearchBar()
    search_query = request.form['query']
    exclude_query = request.form['exclude']
    processed_exclude_query = textProcessing.preprocessText(exclude_query)
    processed_query = textProcessing.preprocessText(search_query)
    query_list = processed_query.split(' ')
    exclude_list = processed_exclude_query.split(' ')
    print('ex: ', exclude_list)
    result_rank_ids = engine.search_keyword(df=engine.df, user_keywords=query_list, user_exclude_keywords=exclude_list).id.to_numpy()
    print("res rank id:", result_rank_ids)
    result_rank_ids = engine.account_clickthrough(query_keywords=query_list, result_list=result_rank_ids, clickthrough=engine.clickthrough)

    result_rank = sortJsonResult(rank_ids=result_rank_ids)

    return render_template(
        'results.html',
        recipeData=result_rank,
        search_query=search_query,
        exclude_query=exclude_query,
        processed_query=processed_query,
        form=search_form,
    )
コード例 #9
0
def index():
    username = session.get('username')
    print(username)
    if not username:
        return redirect(url_for('login'))
    gdb1 = GraphDatabase.driver(bolt_url, auth=basic_auth(usr_nm_db, pswrd_db))
    gdb = gdb1.session()

    form = SearchBar()
    if form.validate_on_submit():
        search_val = form.search.data
        return redirect(url_for('search', var=form.search.data))

    # ---------- THE FOLLOWING BLOCK WILL GENERATE IMDB MOVIE ID ------------------
    query = '''MATCH (u:users {username: '******'})-->(m:Movie)<--(other:users)
    MATCH (other)-->(predict:Movie)
    WHERE not exists((u)-[:VIEWED]->(predict)) and exists(predict.imdbRating)
    with count(predict) as cnt , predict.imdbId as imdbId, predict.imdbRating as rating
    ORDER by cnt  desc
    RETURN distinct imdbId
    limit 5
    ''' % username
    results = gdb.run(query, data_contents=True)
    # results = results.rows[0][0]
    data = []
    results = results.values()
    for res in results:
        print(res)
        data.append(imdbToMovieDetails(res))
    # link = 'https://image.tmdb.org/t/p/original/{}'.format(poster)
    # link2 = 'https://image.tmdb.org/t/p/original/{}'.format(back)
    # ------------------------------------------------------------------
    genrelist = []
    movielist = []
    query = '''match p=(n:users)-[r:likes]->(m:Genre) where n.username="******" return m.name''' % username
    results = gdb.run(query, data_contents=True)
    manjy_list = []
    results = results.value()
    print(results)
    for i in range(len(results)):
        print(i)

        appender = []
        result1 = results[i]
        print(result1)
        genrelist.append(result1)
        # query2 = '''MATCH p=(m:Movie)-[r:IN_GENRE]->(n:Genre{name:'%s'}) where exists(m.imdbRating) RETURN p order by m.imdbRating DESC LIMIT 5''' % (
        #     result1['name'])

        query2 = '''
            MATCH (m:Movie)-[r:IN_GENRE]->(n:Genre)
            WHERE exists(m.imdbRating) and n.name ='%s'
            RETURN m.imdbId
            ORDER BY m.imdbRating DESC
            LIMIT 5
        ''' % result1
        gresults = gdb.run(query2, data_contents=True)

        appender.append(result1)
        for i in gresults:
            appender.append(imdbToMovieDetails(i))

        manjy_list.append(appender)

    query = '''
    match (m:Movie) where exists(m.imdbRating) return m.imdbId order by m.imdbRating DESC limit 2
    '''
    highrate = []
    results = gdb.run(query, data_contents=True)
    results = results.values()
    for res in results:
        highrate.append(imdbToMovieDetails(res))

    return render_template('index.html',
                           data=data,
                           form=form,
                           list=manjy_list,
                           highrate=highrate)
コード例 #10
0
def choose():
    form = SearchBar()
    if form.validate_on_submit():
        search_val = form.search.data
        return redirect(url_for('search', var=search_val))
    return render_template('choose.html', form=form)
コード例 #11
0
def index():
    search_form = SearchBar()
    return render_template('index.html', form=search_form)
コード例 #12
0
def lol():
    find = SearchBar()
    if find.validate_on_submit():
        return redirect(url_for('found'))
    return render_template("lol.html", title='lol', find=find)
コード例 #13
0
def hello():
    find = SearchBar()
    if find.validate_on_submit():
        #if request.method == 'POST':
        return redirect(url_for('found'))
    return render_template('home.html', data=data, find=find)