forked from Ponysearch/Ponysearch
[mod] search return value
This commit is contained in:
parent
4cc79533e7
commit
d1b12f9016
2 changed files with 13 additions and 17 deletions
|
@ -329,8 +329,8 @@ class Search(object):
|
||||||
self.blocked_engines = get_blocked_engines(engines, request.cookies)
|
self.blocked_engines = get_blocked_engines(engines, request.cookies)
|
||||||
|
|
||||||
self.results = []
|
self.results = []
|
||||||
self.suggestions = []
|
self.suggestions = set()
|
||||||
self.answers = []
|
self.answers = set()
|
||||||
self.infoboxes = []
|
self.infoboxes = []
|
||||||
self.request_data = {}
|
self.request_data = {}
|
||||||
|
|
||||||
|
@ -429,9 +429,6 @@ class Search(object):
|
||||||
requests = []
|
requests = []
|
||||||
results_queue = Queue()
|
results_queue = Queue()
|
||||||
results = {}
|
results = {}
|
||||||
suggestions = set()
|
|
||||||
answers = set()
|
|
||||||
infoboxes = []
|
|
||||||
|
|
||||||
# increase number of searches
|
# increase number of searches
|
||||||
number_of_searches += 1
|
number_of_searches += 1
|
||||||
|
@ -511,7 +508,7 @@ class Search(object):
|
||||||
selected_engine['name']))
|
selected_engine['name']))
|
||||||
|
|
||||||
if not requests:
|
if not requests:
|
||||||
return results, suggestions, answers, infoboxes
|
return self
|
||||||
# send all search-request
|
# send all search-request
|
||||||
threaded_requests(requests)
|
threaded_requests(requests)
|
||||||
|
|
||||||
|
@ -519,17 +516,17 @@ class Search(object):
|
||||||
engine_name, engine_results = results_queue.get_nowait()
|
engine_name, engine_results = results_queue.get_nowait()
|
||||||
|
|
||||||
# TODO type checks
|
# TODO type checks
|
||||||
[suggestions.add(x['suggestion'])
|
[self.suggestions.add(x['suggestion'])
|
||||||
for x in list(engine_results)
|
for x in list(engine_results)
|
||||||
if 'suggestion' in x
|
if 'suggestion' in x
|
||||||
and engine_results.remove(x) is None]
|
and engine_results.remove(x) is None]
|
||||||
|
|
||||||
[answers.add(x['answer'])
|
[self.answers.add(x['answer'])
|
||||||
for x in list(engine_results)
|
for x in list(engine_results)
|
||||||
if 'answer' in x
|
if 'answer' in x
|
||||||
and engine_results.remove(x) is None]
|
and engine_results.remove(x) is None]
|
||||||
|
|
||||||
infoboxes.extend(x for x in list(engine_results)
|
self.infoboxes.extend(x for x in list(engine_results)
|
||||||
if 'infobox' in x
|
if 'infobox' in x
|
||||||
and engine_results.remove(x) is None)
|
and engine_results.remove(x) is None)
|
||||||
|
|
||||||
|
@ -541,16 +538,16 @@ class Search(object):
|
||||||
engines[engine_name].stats['result_count'] += len(engine_results)
|
engines[engine_name].stats['result_count'] += len(engine_results)
|
||||||
|
|
||||||
# score results and remove duplications
|
# score results and remove duplications
|
||||||
results = score_results(results)
|
self.results = score_results(results)
|
||||||
|
|
||||||
# merge infoboxes according to their ids
|
# merge infoboxes according to their ids
|
||||||
infoboxes = merge_infoboxes(infoboxes)
|
self.infoboxes = merge_infoboxes(self.infoboxes)
|
||||||
|
|
||||||
# update engine stats, using calculated score
|
# update engine stats, using calculated score
|
||||||
for result in results:
|
for result in self.results:
|
||||||
for res_engine in result['engines']:
|
for res_engine in result['engines']:
|
||||||
engines[result['engine']]\
|
engines[result['engine']]\
|
||||||
.stats['score_count'] += result['score']
|
.stats['score_count'] += result['score']
|
||||||
|
|
||||||
# return results, suggestions, answers and infoboxes
|
# return results, suggestions, answers and infoboxes
|
||||||
return results, suggestions, answers, infoboxes
|
return self
|
||||||
|
|
|
@ -323,8 +323,7 @@ def index():
|
||||||
'index.html',
|
'index.html',
|
||||||
)
|
)
|
||||||
|
|
||||||
search.results, search.suggestions,\
|
search.search(request)
|
||||||
search.answers, search.infoboxes = search.search(request)
|
|
||||||
|
|
||||||
for result in search.results:
|
for result in search.results:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue