From 3d044b6ce44f0d7ef29bfc961eac42f722fca289 Mon Sep 17 00:00:00 2001 From: Ben Cohen Date: Sun, 28 Jul 2019 20:07:08 -0400 Subject: search! --- app.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/app.py b/app.py index beee1d5..5c4fdde 100644 --- a/app.py +++ b/app.py @@ -127,22 +127,22 @@ def get_all_beers(): if not q: return redirect('/') - return jsonify([orig_term_map[x] for x in search(q)]) + return jsonify([orig_term_map[x] for x in search_term(q)]) # return jsonify(names[0:20]) -# @app.route('/search', methods=['POST']) -# def search(): -# q = request.form.get('q') -# if not q: -# return redirect('/') -# brewery, beer_name = q.split(' — ') -# print('SEARCHING: ', q) -# beer_id, brewery_id = name_list[q].split('-') -# return redirect(url_for('get_beer_details', beer_id=beer_id, brewery_id=brewery_id)) +@app.route('/search', methods=['POST']) +def search(): + q = request.form.get('q') + if not q: + return redirect('/') + brewery, beer_name = q.split(' — ') + print('SEARCHING: ', q) + beer_id, brewery_id = name_list[q].split('-') + return redirect(url_for('get_beer_details', beer_id=beer_id, brewery_id=brewery_id)) -def search(query): +def search_term(query): query = query.lower() query = ''.join(x for x in query if x not in string.punctuation) print(query) @@ -152,8 +152,11 @@ def search(query): matches = [x for x in search_words if term in x] # print(matches) for m in matches: - all_matches[m] += 1/len(matches)/len(m) + if m in all_matches: + all_matches[m] += .05 + all_matches[m] += (1/len(matches)) + print(all_matches) return sorted(all_matches, key=lambda x: all_matches[x], reverse=True)[:10] -- cgit v1.2.3