diff options
| author | Alexandre Flament <alex@al-f.net> | 2020-12-16 13:41:32 +0100 |
|---|---|---|
| committer | Alexandre Flament <alex@al-f.net> | 2020-12-17 11:39:36 +0100 |
| commit | 7ec8bc3ea76516e33318c67165161df5c1efdd36 (patch) | |
| tree | 6c9dff310882db816cada8662ef5ed2b8a8158e8 /searx/search/processors/offline.py | |
| parent | c0cc01e936593ff3df828fa3bb834507c45cd7ac (diff) | |
[mod] split searx.search into different processors
see searx.search.processors.abstract.EngineProcessor
First the method searx call the get_params method.
If the return value is not None, then the searx call the method search.
Diffstat (limited to 'searx/search/processors/offline.py')
| -rw-r--r-- | searx/search/processors/offline.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/searx/search/processors/offline.py b/searx/search/processors/offline.py new file mode 100644 index 000000000..ede8eb5e1 --- /dev/null +++ b/searx/search/processors/offline.py @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later + +import threading +from time import time +from searx import logger +from searx.metrology.error_recorder import record_exception, record_error +from searx.search.processors.abstract import EngineProcessor + + +logger = logger.getChild('search.processor.offline') + + +class OfflineProcessor(EngineProcessor): + + engine_type = 'offline' + + def _record_stats_on_error(self, result_container, start_time): + engine_time = time() - start_time + result_container.add_timing(self.engine_name, engine_time, engine_time) + + with threading.RLock(): + self.engine.stats['errors'] += 1 + + def _search_basic(self, query, params): + return self.engine.search(query, params) + + def search(self, query, params, result_container, start_time, timeout_limit): + try: + search_results = self._search_basic(query, params) + + if search_results: + result_container.extend(self.engine_name, search_results) + + engine_time = time() - start_time + result_container.add_timing(self.engine_name, engine_time, engine_time) + with threading.RLock(): + self.engine.stats['engine_time'] += engine_time + self.engine.stats['engine_time_count'] += 1 + + except ValueError as e: + record_exception(self.engine_name, e) + self._record_stats_on_error(result_container, start_time) + logger.exception('engine {0} : invalid input : {1}'.format(self.engine_name, e)) + except Exception as e: + record_exception(self.engine_name, e) + self._record_stats_on_error(result_container, start_time) + result_container.add_unresponsive_engine(self.engine_name, 'unexpected crash', str(e)) + logger.exception('engine {0} : exception : {1}'.format(self.engine_name, e)) + else: + if getattr(threading.current_thread(), '_timeout', False): + record_error(self.engine_name, 'Timeout') |