mirror of
https://github.com/searxng/searxng
synced 2024-01-01 18:24:07 +00:00
[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():
|
||||
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 = []
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user