diff options
author | asciimoo <asciimoo@gmail.com> | 2013-10-22 18:57:20 +0200 |
---|---|---|
committer | asciimoo <asciimoo@gmail.com> | 2013-10-22 18:57:20 +0200 |
commit | 8520be3cd6bb2ae4aa4ee483f632ef7fca318e1a (patch) | |
tree | 8cdc924111c3a1ca6c8449cef7013ea84a837b0e /searx/engines | |
parent | f01b1dc2cef5d3c9a4504df171f77007106019d5 (diff) | |
download | searxng-8520be3cd6bb2ae4aa4ee483f632ef7fca318e1a.tar.gz searxng-8520be3cd6bb2ae4aa4ee483f632ef7fca318e1a.zip |
[enh] categories to request callback
Diffstat (limited to 'searx/engines')
-rw-r--r-- | searx/engines/__init__.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index aa329269e..8339a13dc 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -61,18 +61,25 @@ def make_callback(engine_name, results, callback): results[engine_name] = cb_res return process_callback -def search(query, request, selected_engines): - global engines +def search(query, request, selected_categories): + global engines, categories requests = [] results = {} + selected_engines = [] user_agent = request.headers.get('User-Agent', '') - for ename, engine in engines.items(): - if ename not in selected_engines: + if not len(selected_categories): + selected_categories = ['general'] + for categ in selected_categories: + selected_engines.extend({'category': categ, 'name': x.name} for x in categories[categ]) + for selected_engine in selected_engines: + if selected_engine['name'] not in engines: continue + engine = engines[selected_engine['name']] request_params = default_request_params() request_params['headers']['User-Agent'] = user_agent + request_params['category'] = selected_engine['category'] request_params = engine.request(query, request_params) - callback = make_callback(ename, results, engine.response) + callback = make_callback(selected_engine['name'], results, engine.response) if request_params['method'] == 'GET': req = grequests.get(request_params['url'] ,headers=request_params['headers'] |