diff options
author | Markus Heiser <markus.heiser@darmarit.de> | 2023-06-18 16:43:48 +0200 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarIT.de> | 2023-06-19 19:49:44 +0200 |
commit | fa1ef9a07b79ab740c127bac0d11b8315a5130ff (patch) | |
tree | 80306333c2e5a13a0b3a286e7dad7b5df633689e /searx/results.py | |
parent | 71b6ff07ca137a39576c3084abec348ded40564e (diff) | |
download | searxng-fa1ef9a07b79ab740c127bac0d11b8315a5130ff.tar.gz searxng-fa1ef9a07b79ab740c127bac0d11b8315a5130ff.zip |
[mod] move some code from webapp module to webutils module (no functional change)
Over the years the webapp module became more and more a mess. To improve the
modulaization a little this patch moves some implementations from the webapp
module to webutils module.
HINT: this patch brings non functional change
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/results.py')
-rw-r--r-- | searx/results.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/searx/results.py b/searx/results.py index 5dd1bff21..caf02213d 100644 --- a/searx/results.py +++ b/searx/results.py @@ -6,6 +6,7 @@ from typing import List, NamedTuple, Set from urllib.parse import urlparse, unquote from searx import logger +from searx import utils from searx.engines import engines from searx.metrics import histogram_observe, counter_add, count_error @@ -353,6 +354,10 @@ class ResultContainer: for result in self._merged_results: score = result_score(result) result['score'] = score + if result.get('content'): + result['content'] = utils.html_to_text(result['content']).strip() + # removing html content and whitespace duplications + result['title'] = ' '.join(utils.html_to_text(result['title']).strip().split()) for result_engine in result['engines']: counter_add(score, 'engine', result_engine, 'score') @@ -415,11 +420,19 @@ class ResultContainer: def results_length(self): return len(self._merged_results) - def results_number(self): + @property + def number_of_results(self) -> int: + """Returns the average of results number, returns zero if the average + result number is smaller than the actual result count.""" + 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) + + average = int(resultnum_sum / len(self._number_of_results)) + if average < self.results_length(): + average = 0 + return average def add_unresponsive_engine(self, engine_name: str, error_type: str, suspended: bool = False): if engines[engine_name].display_error_messages: |