2020-12-16 13:41:32 +01:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2025-09-11 19:10:27 +02:00
|
|
|
"""Processors for engine-type: ``offline``"""
|
2020-12-16 13:41:32 +01:00
|
|
|
|
2025-09-11 19:10:27 +02:00
|
|
|
import typing as t
|
|
|
|
|
from .abstract import EngineProcessor, RequestParams
|
2020-12-16 13:41:32 +01:00
|
|
|
|
2025-09-11 19:10:27 +02:00
|
|
|
if t.TYPE_CHECKING:
|
|
|
|
|
from searx.results import ResultContainer
|
2020-12-16 13:41:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class OfflineProcessor(EngineProcessor):
|
2025-09-11 19:10:27 +02:00
|
|
|
"""Processor class used by ``offline`` engines."""
|
2020-12-16 13:41:32 +01:00
|
|
|
|
2025-09-11 19:10:27 +02:00
|
|
|
engine_type: str = "offline"
|
2020-12-16 13:41:32 +01:00
|
|
|
|
2025-09-11 19:10:27 +02:00
|
|
|
def search(
|
|
|
|
|
self,
|
|
|
|
|
query: str,
|
|
|
|
|
params: RequestParams,
|
|
|
|
|
result_container: "ResultContainer",
|
|
|
|
|
start_time: float,
|
|
|
|
|
timeout_limit: float,
|
|
|
|
|
):
|
2020-12-16 13:41:32 +01:00
|
|
|
try:
|
2025-09-11 19:10:27 +02:00
|
|
|
search_results = self.engine.search(query, params)
|
2021-04-13 15:21:53 +02:00
|
|
|
self.extend_container(result_container, start_time, search_results)
|
2020-12-16 13:41:32 +01:00
|
|
|
except ValueError as e:
|
2021-04-13 15:21:53 +02:00
|
|
|
# do not record the error
|
2025-09-11 19:10:27 +02:00
|
|
|
self.logger.exception('engine {0} : invalid input : {1}'.format(self.engine.name, e))
|
2021-12-27 09:26:22 +01:00
|
|
|
except Exception as e: # pylint: disable=broad-except
|
2021-04-26 11:12:02 +02:00
|
|
|
self.handle_exception(result_container, e)
|
2025-09-11 19:10:27 +02:00
|
|
|
self.logger.exception('engine {0} : exception : {1}'.format(self.engine.name, e))
|