From 7d19e0d1903f2842ebe04607c45ef1b8dd4ec2d0 Mon Sep 17 00:00:00 2001 From: Arvind Date: Sat, 30 Mar 2013 10:24:10 +0530 Subject: [PATCH] Fixing API - /search will accept an array of keywords and run a search. --- fetch.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/fetch.py b/fetch.py index b1249ed..8a96afc 100644 --- a/fetch.py +++ b/fetch.py @@ -50,15 +50,21 @@ def search(): collection = db['data'] y = 0 ret = {} + keywords_dict = json.loads(request.args['data']) + keywords = json.loads(keywords_dict)['data'] for i in collection.find(): - try: - if request.args['data'] in i['nodes']: - del(i['_id']) - ret[y] = i - y = y + 1 - except: - pass + for keyword in keywords: + print keyword + try: + if keyword in i['nodes']: + del(i['_id']) + ret[y] = i + y = y + 1 + except: + pass return render_template('blank.html', content = ret) + + @app.route('/submit', methods=['POST']) def submit(): c = pymongo.Connection() -- 1.7.10.4