mirror of
https://github.com/searxng/searxng.git
synced 2024-11-17 18:00:12 +01:00
[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._infobox_ids = {}
|
||||||
self.suggestions = set()
|
self.suggestions = set()
|
||||||
self.answers = set()
|
self.answers = set()
|
||||||
self.number_of_results = 0
|
self._number_of_results = []
|
||||||
|
|
||||||
def extend(self, engine_name, results):
|
def extend(self, engine_name, results):
|
||||||
for result in list(results):
|
for result in list(results):
|
||||||
@ -114,7 +114,7 @@ class ResultContainer(object):
|
|||||||
self._merge_infobox(result)
|
self._merge_infobox(result)
|
||||||
results.remove(result)
|
results.remove(result)
|
||||||
elif 'number_of_results' in 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)
|
results.remove(result)
|
||||||
|
|
||||||
with RLock():
|
with RLock():
|
||||||
@ -253,3 +253,9 @@ class ResultContainer(object):
|
|||||||
|
|
||||||
def results_length(self):
|
def results_length(self):
|
||||||
return len(self._merged_results)
|
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:
|
else:
|
||||||
result['publishedDate'] = format_date(result['publishedDate'])
|
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':
|
if search.request_data.get('format') == 'json':
|
||||||
return Response(json.dumps({'query': search.query,
|
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()}),
|
'results': search.result_container.get_ordered_results()}),
|
||||||
mimetype='application/json')
|
mimetype='application/json')
|
||||||
elif search.request_data.get('format') == 'csv':
|
elif search.request_data.get('format') == 'csv':
|
||||||
@ -440,7 +444,7 @@ def index():
|
|||||||
'opensearch_response_rss.xml',
|
'opensearch_response_rss.xml',
|
||||||
results=search.result_container.get_ordered_results(),
|
results=search.result_container.get_ordered_results(),
|
||||||
q=search.request_data['q'],
|
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()
|
base_url=get_base_url()
|
||||||
)
|
)
|
||||||
return Response(response_rss, mimetype='text/xml')
|
return Response(response_rss, mimetype='text/xml')
|
||||||
@ -451,7 +455,7 @@ def index():
|
|||||||
q=search.request_data['q'],
|
q=search.request_data['q'],
|
||||||
selected_categories=search.categories,
|
selected_categories=search.categories,
|
||||||
paging=search.paging,
|
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,
|
pageno=search.pageno,
|
||||||
base_url=get_base_url(),
|
base_url=get_base_url(),
|
||||||
suggestions=search.result_container.suggestions,
|
suggestions=search.result_container.suggestions,
|
||||||
|
Loading…
Reference in New Issue
Block a user