[mod] searching by selected engines

This commit is contained in:
asciimoo 2013-11-04 00:18:07 +01:00
parent d2a952ecdf
commit 70278567ec
2 changed files with 12 additions and 10 deletions

View file

@ -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

View file

@ -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:]