From 70278567ecacd1632dfdfdff6dbcc0f14a8fab02 Mon Sep 17 00:00:00 2001 From: asciimoo Date: Mon, 4 Nov 2013 00:18:07 +0100 Subject: [PATCH] [mod] searching by selected engines --- searx/engines/__init__.py | 9 +-------- searx/webapp.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 7ea9e7652..85c9be4d8 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -97,20 +97,13 @@ def make_callback(engine_name, results, callback, params): results[engine_name] = cb_res return process_callback -def search(query, request, selected_categories): +def search(query, request, selected_engines): global engines, categories, number_of_searches requests = [] results = {} - selected_engines = [] number_of_searches += 1 user_agent = request.headers.get('User-Agent', '') - if not len(selected_categories): - selected_categories = ['general'] - - for categ in selected_categories: - selected_engines.extend({'category': categ, 'name': x.name} for x in categories[categ]) - for selected_engine in selected_engines: if selected_engine['name'] not in engines: continue diff --git a/searx/webapp.py b/searx/webapp.py index 86fd4dcfe..6dad9efc2 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -65,6 +65,9 @@ def index(): request_data = request.args if not request_data.get('q'): return render('index.html') + + query = request_data['q'].encode('utf-8') + selected_categories = [] for pd_name,pd in request_data.items(): if pd_name.startswith('category_'): @@ -77,8 +80,14 @@ def index(): for ccateg in cookie_categories: if ccateg in categories: selected_categories.append(ccateg) - query = request_data['q'].encode('utf-8') - results = search(query, request, selected_categories) + if not len(selected_categories): + selected_categories = ['general'] + + selected_engines = [] + for categ in selected_categories: + selected_engines.extend({'category': categ, 'name': x.name} for x in categories[categ]) + + results = search(query, request, selected_engines) for result in results: if len(result['url']) > 74: result['pretty_url'] = result['url'][:35] + '[..]' + result['url'][-35:]