forked from zaclys/searxng
[enh] suggestion support added
This commit is contained in:
parent
9688495b9f
commit
66ff28bb9d
|
@ -83,7 +83,7 @@ for engine_config_name in engines_config.sections():
|
||||||
def default_request_params():
|
def default_request_params():
|
||||||
return {'method': 'GET', 'headers': {}, 'data': {}, 'url': '', 'cookies': {}}
|
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
|
# creating a callback wrapper for the search engine results
|
||||||
def process_callback(response, **kwargs):
|
def process_callback(response, **kwargs):
|
||||||
cb_res = []
|
cb_res = []
|
||||||
|
@ -98,6 +98,10 @@ def make_callback(engine_name, results, callback, params):
|
||||||
return
|
return
|
||||||
for result in search_results:
|
for result in search_results:
|
||||||
result['engine'] = engine_name
|
result['engine'] = engine_name
|
||||||
|
if 'suggestion' in result:
|
||||||
|
# TODO type checks
|
||||||
|
suggestions.add(result['suggestion'])
|
||||||
|
continue
|
||||||
cb_res.append(result)
|
cb_res.append(result)
|
||||||
results[engine_name] = cb_res
|
results[engine_name] = cb_res
|
||||||
return process_callback
|
return process_callback
|
||||||
|
@ -167,6 +171,7 @@ def search(query, request, selected_engines):
|
||||||
global engines, categories, number_of_searches
|
global engines, categories, number_of_searches
|
||||||
requests = []
|
requests = []
|
||||||
results = {}
|
results = {}
|
||||||
|
suggestions = set()
|
||||||
number_of_searches += 1
|
number_of_searches += 1
|
||||||
user_agent = request.headers.get('User-Agent', '')
|
user_agent = request.headers.get('User-Agent', '')
|
||||||
|
|
||||||
|
@ -182,7 +187,7 @@ def search(query, request, selected_engines):
|
||||||
request_params['started'] = datetime.now()
|
request_params['started'] = datetime.now()
|
||||||
request_params = engine.request(query, request_params)
|
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']
|
request_args = dict(headers = request_params['headers']
|
||||||
,hooks = dict(response=callback)
|
,hooks = dict(response=callback)
|
||||||
|
@ -214,7 +219,7 @@ def search(query, request, selected_engines):
|
||||||
for res_engine in result['engines']:
|
for res_engine in result['engines']:
|
||||||
engines[result['engine']].stats['score_count'] += result['score']
|
engines[result['engine']].stats['score_count'] += result['score']
|
||||||
|
|
||||||
return results
|
return results, suggestions
|
||||||
|
|
||||||
def get_engines_stats():
|
def get_engines_stats():
|
||||||
pageloads = []
|
pageloads = []
|
||||||
|
|
|
@ -96,7 +96,7 @@ def index():
|
||||||
for categ in selected_categories:
|
for categ in selected_categories:
|
||||||
selected_engines.extend({'category': categ, 'name': x.name} for x in categories[categ])
|
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:
|
for result in results:
|
||||||
if len(result['url']) > 74:
|
if len(result['url']) > 74:
|
||||||
result['pretty_url'] = result['url'][:35] + '[..]' + result['url'][-35:]
|
result['pretty_url'] = result['url'][:35] + '[..]' + result['url'][-35:]
|
||||||
|
@ -109,6 +109,7 @@ def index():
|
||||||
,q=request_data['q']
|
,q=request_data['q']
|
||||||
,selected_categories=selected_categories
|
,selected_categories=selected_categories
|
||||||
,number_of_results=len(results)
|
,number_of_results=len(results)
|
||||||
|
,suggestions=suggestions
|
||||||
)
|
)
|
||||||
resp = make_response(template)
|
resp = make_response(template)
|
||||||
resp.set_cookie('categories', ','.join(selected_categories))
|
resp.set_cookie('categories', ','.join(selected_categories))
|
||||||
|
|
Loading…
Reference in New Issue