mirror of https://github.com/searxng/searxng.git
[mod][fix] use the average of results number ++ do not display smaller result number than the actual result count - closes #600
This commit is contained in:
parent
9393887eac
commit
485da54961
|
@ -100,7 +100,7 @@ class ResultContainer(object):
|
|||
self._infobox_ids = {}
|
||||
self.suggestions = set()
|
||||
self.answers = set()
|
||||
self.number_of_results = 0
|
||||
self._number_of_results = []
|
||||
|
||||
def extend(self, engine_name, results):
|
||||
for result in list(results):
|
||||
|
@ -114,7 +114,7 @@ class ResultContainer(object):
|
|||
self._merge_infobox(result)
|
||||
results.remove(result)
|
||||
elif 'number_of_results' in result:
|
||||
self.number_of_results = max(self.number_of_results, result['number_of_results'])
|
||||
self._number_of_results.append(result['number_of_results'])
|
||||
results.remove(result)
|
||||
|
||||
with RLock():
|
||||
|
@ -253,3 +253,9 @@ class ResultContainer(object):
|
|||
|
||||
def results_length(self):
|
||||
return len(self._merged_results)
|
||||
|
||||
def results_number(self):
|
||||
resultnum_sum = sum(self._number_of_results)
|
||||
if not resultnum_sum or not self._number_of_results:
|
||||
return 0
|
||||
return resultnum_sum / len(self._number_of_results)
|
||||
|
|
|
@ -418,9 +418,13 @@ def index():
|
|||
else:
|
||||
result['publishedDate'] = format_date(result['publishedDate'])
|
||||
|
||||
number_of_results = search.result_container.results_number()
|
||||
if number_of_results < search.result_container.results_length():
|
||||
number_of_results = 0
|
||||
|
||||
if search.request_data.get('format') == 'json':
|
||||
return Response(json.dumps({'query': search.query,
|
||||
'number_of_results': search.result_container.number_of_results,
|
||||
'number_of_results': number_of_results,
|
||||
'results': search.result_container.get_ordered_results()}),
|
||||
mimetype='application/json')
|
||||
elif search.request_data.get('format') == 'csv':
|
||||
|
@ -440,7 +444,7 @@ def index():
|
|||
'opensearch_response_rss.xml',
|
||||
results=search.result_container.get_ordered_results(),
|
||||
q=search.request_data['q'],
|
||||
number_of_results=search.result_container.number_of_results,
|
||||
number_of_results=number_of_results,
|
||||
base_url=get_base_url()
|
||||
)
|
||||
return Response(response_rss, mimetype='text/xml')
|
||||
|
@ -451,7 +455,7 @@ def index():
|
|||
q=search.request_data['q'],
|
||||
selected_categories=search.categories,
|
||||
paging=search.paging,
|
||||
number_of_results=format_decimal(search.result_container.number_of_results),
|
||||
number_of_results=format_decimal(number_of_results),
|
||||
pageno=search.pageno,
|
||||
base_url=get_base_url(),
|
||||
suggestions=search.result_container.suggestions,
|
||||
|
|
Loading…
Reference in New Issue