diff options
author | Ben Cohen <ben@kensho.com> | 2019-07-28 20:07:08 -0400 |
---|---|---|
committer | Ben Cohen <ben@kensho.com> | 2019-07-28 20:07:08 -0400 |
commit | 3d044b6ce44f0d7ef29bfc961eac42f722fca289 (patch) | |
tree | 669639676275013917a5973504ee9f938ccaf7a7 | |
parent | 89a2f78d297432f01e87dc4797e5f44a2bb2471d (diff) |
search!
-rw-r--r-- | app.py | 27 |
1 files changed, 15 insertions, 12 deletions
@@ -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] |