on master help sign in
[fix] use queues to answers/suggestions/infoboxes
commitd93d7037036d7035c1419dcb91ba8e535d15e0cf authorAdam Tauber <asciimoo@gmail.com> dateSun 14 Dec 2014, 02:15 (12 years ago) parenta5324d9
1 file changed+18−22
searx/search.py+18−22
searx/search.py+18−22
@@ -73,7 +73,6 @@ def make_callback(engine_name,
7373
7474 # creating a callback wrapper for the search engine results
7575 def process_callback(response, **kwargs):
76− cb_res = []
7776 response.search_params = params
7877
7978 # callback
@@ -82,7 +81,6 @@ def make_callback(engine_name,
8281 except Exception, e:
8382 # increase errors stats
8483 engines[engine_name].stats['errors'] += 1
85− results_queue.put_nowait((engine_name, cb_res))
8684
8785 # print engine name and specific error message
8886 print '[E] Error with engine "{0}":\n\t{1}'.format(
@@ -93,26 +91,7 @@ def make_callback(engine_name,
9391 for result in search_results:
9492 result['engine'] = engine_name
9593
96− # if it is a suggestion, add it to list of suggestions
97− if 'suggestion' in result:
98− # TODO type checks
99− suggestions.add(result['suggestion'])
100− continue
101−
102− # if it is an answer, add it to list of answers
103− if 'answer' in result:
104− answers.add(result['answer'])
105− continue
106−
107− # if it is an infobox, add it to list of infoboxes
108− if 'infobox' in result:
109− infoboxes.append(result)
110− continue
111−
112− # append result
113− cb_res.append(result)
114−
115− results_queue.put_nowait((engine_name, cb_res))
94+ results_queue.put_nowait((engine_name, search_results))
11695
11796 # update stats with current page-load-time
11897 engines[engine_name].stats['page_load_time'] += \
@@ -511,8 +490,25 @@ class Search(object):
511490 threaded_requests(requests)
512491
513492 results = {}
493+
514494 while not results_queue.empty():
515495 engine_name, engine_results = results_queue.get_nowait()
496+
497+ # TODO type checks
498+ [suggestions.add(x['suggestion'])
499+ for x in list(engine_results)
500+ if 'suggestion' in x
501+ and engine_results.remove(x) is None]
502+
503+ [answers.add(x['answer'])
504+ for x in list(engine_results)
505+ if 'answer' in x
506+ and engine_results.remove(x) is None]
507+
508+ infoboxes.extend(x for x in list(engine_results)
509+ if 'infobox' in x
510+ and engine_results.remove(x) is None)
511+
516512 results[engine_name] = engine_results
517513
518514 # update engine-specific stats