logo

searx

Unnamed repository; edit this file 'description' to name the repository.
commit: 485da54961d3cdbc4e3fd33fab90fea6407932ea
parent: 9393887eac297fd0007382f62e818a90b283d63b
Author: Adam Tauber <asciimoo@gmail.com>
Date:   Sat, 16 Jul 2016 21:37:40 +0200

[mod][fix] use the average of results number ++ do not display smaller result number than the actual result count - closes #600

Diffstat:

searx/results.py | 10++++++++--
searx/webapp.py | 10+++++++---
2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/searx/results.py b/searx/results.py @@ -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) diff --git a/searx/webapp.py b/searx/webapp.py @@ -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,