summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorasciimoo <asciimoo@gmail.com>2013-11-13 19:32:46 +0100
committerasciimoo <asciimoo@gmail.com>2013-11-13 19:32:46 +0100
commit66ff28bb9deddcd2eb88186e45cc86d31587b636 (patch)
tree9956178141aff36b2093cda140e7799b1359a691
parent9688495b9fd3f03c2faaf95ec23f03b9533682b1 (diff)
downloadsearxng-66ff28bb9deddcd2eb88186e45cc86d31587b636.tar.gz
searxng-66ff28bb9deddcd2eb88186e45cc86d31587b636.zip
[enh] suggestion support added
-rw-r--r--searx/engines/__init__.py11
-rw-r--r--searx/webapp.py3
2 files changed, 10 insertions, 4 deletions
diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py
index 7e545d5e7..3a74c9f2a 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 4fb4e4584..9185f46a3 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))