forked from zaclys/searxng
[enh] result ordering
This commit is contained in:
parent
c4dfd416ad
commit
a346327c6f
|
@ -3,6 +3,7 @@ from os.path import realpath, dirname, splitext, join
|
||||||
from os import listdir
|
from os import listdir
|
||||||
from imp import load_source
|
from imp import load_source
|
||||||
import grequests
|
import grequests
|
||||||
|
from itertools import izip_longest, chain
|
||||||
|
|
||||||
engine_dir = dirname(realpath(__file__))
|
engine_dir = dirname(realpath(__file__))
|
||||||
|
|
||||||
|
@ -23,15 +24,17 @@ def default_request_params():
|
||||||
|
|
||||||
def make_callback(engine_name, results, callback):
|
def make_callback(engine_name, results, callback):
|
||||||
def process_callback(response, **kwargs):
|
def process_callback(response, **kwargs):
|
||||||
|
cb_res = []
|
||||||
for result in callback(response):
|
for result in callback(response):
|
||||||
result['engine'] = engine_name
|
result['engine'] = engine_name
|
||||||
results.append(result)
|
cb_res.append(result)
|
||||||
|
results[engine_name] = cb_res
|
||||||
return process_callback
|
return process_callback
|
||||||
|
|
||||||
def search(query, request, selected_engines):
|
def search(query, request, selected_engines):
|
||||||
global engines
|
global engines
|
||||||
requests = []
|
requests = []
|
||||||
results = []
|
results = {}
|
||||||
user_agent = request.headers.get('User-Agent', '')
|
user_agent = request.headers.get('User-Agent', '')
|
||||||
for ename, engine in engines.items():
|
for ename, engine in engines.items():
|
||||||
if ename not in selected_engines:
|
if ename not in selected_engines:
|
||||||
|
@ -53,4 +56,4 @@ def search(query, request, selected_engines):
|
||||||
)
|
)
|
||||||
requests.append(req)
|
requests.append(req)
|
||||||
grequests.map(requests)
|
grequests.map(requests)
|
||||||
return results
|
return list(filter(None, chain(*izip_longest(*results.values()))))
|
||||||
|
|
Loading…
Reference in New Issue