From 66ff28bb9deddcd2eb88186e45cc86d31587b636 Mon Sep 17 00:00:00 2001 From: asciimoo Date: Wed, 13 Nov 2013 19:32:46 +0100 Subject: [PATCH] [enh] suggestion support added --- searx/engines/__init__.py | 11 ++++++++--- searx/webapp.py | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 7e545d5e..3a74c9f2 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -83,7 +83,7 @@ for engine_config_name in engines_config.sections(): def default_request_params(): return {'method': 'GET', 'headers': {}, 'data': {}, 'url': '', 'cookies': {}} -def make_callback(engine_name, results, callback, params): +def make_callback(engine_name, results, suggestions, callback, params): # creating a callback wrapper for the search engine results def process_callback(response, **kwargs): cb_res = [] @@ -98,6 +98,10 @@ def make_callback(engine_name, results, callback, params): return for result in search_results: result['engine'] = engine_name + if 'suggestion' in result: + # TODO type checks + suggestions.add(result['suggestion']) + continue cb_res.append(result) results[engine_name] = cb_res return process_callback @@ -167,6 +171,7 @@ def search(query, request, selected_engines): global engines, categories, number_of_searches requests = [] results = {} + suggestions = set() number_of_searches += 1 user_agent = request.headers.get('User-Agent', '') @@ -182,7 +187,7 @@ def search(query, request, selected_engines): request_params['started'] = datetime.now() request_params = engine.request(query, request_params) - callback = make_callback(selected_engine['name'], results, engine.response, request_params) + callback = make_callback(selected_engine['name'], results, suggestions, engine.response, request_params) request_args = dict(headers = request_params['headers'] ,hooks = dict(response=callback) @@ -214,7 +219,7 @@ def search(query, request, selected_engines): for res_engine in result['engines']: engines[result['engine']].stats['score_count'] += result['score'] - return results + return results, suggestions def get_engines_stats(): pageloads = [] diff --git a/searx/webapp.py b/searx/webapp.py index 4fb4e458..9185f46a 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -96,7 +96,7 @@ def index(): for categ in selected_categories: selected_engines.extend({'category': categ, 'name': x.name} for x in categories[categ]) - results = search(query, request, selected_engines) + results, suggestions = search(query, request, selected_engines) for result in results: if len(result['url']) > 74: result['pretty_url'] = result['url'][:35] + '[..]' + result['url'][-35:] @@ -109,6 +109,7 @@ def index(): ,q=request_data['q'] ,selected_categories=selected_categories ,number_of_results=len(results) + ,suggestions=suggestions ) resp = make_response(template) resp.set_cookie('categories', ','.join(selected_categories))