Source code for

# SPDX-License-Identifier: AGPL-3.0-or-later
# lint: pylint
# pylint: disable=missing-module-docstring, too-few-public-methods

import typing
import threading
from timeit import default_timer
from uuid import uuid4

from searx import settings
from searx.answerers import ask
from searx.external_bang import get_bang_url
from searx.results import ResultContainer
from searx import logger
from searx.plugins import plugins
from import EngineRef, SearchQuery
from searx.engines import load_engines
from import initialize as initialize_network, check_network_configuration
from searx.metrics import initialize as initialize_metrics, counter_inc, histogram_observe_time
from import PROCESSORS, initialize as initialize_processors
from import initialize as initialize_checker

logger = logger.getChild('search')

def initialize(settings_engines=None, enable_checker=False, check_network=False):
    settings_engines = settings_engines or settings['engines']
    initialize_network(settings_engines, settings['outgoing'])
    if check_network:
    initialize_metrics([engine['name'] for engine in settings_engines])
    if enable_checker:

[docs]class SearchWithPlugins(Search): """Inherit from the Search class, add calls to the plugins.""" __slots__ = 'ordered_plugin_list', 'request' def __init__(self, search_query: SearchQuery, ordered_plugin_list, request: "flask.Request"): super().__init__(search_query) self.ordered_plugin_list = ordered_plugin_list self.result_container.on_result = self._on_result # pylint: disable=line-too-long # get the "real" request to use it outside the Flask context. # see # * # * # * # pylint: enable=line-too-long self.request = request._get_current_object() def _on_result(self, result): return, 'on_result', self.request, self, result)
[docs] def search(self) -> ResultContainer: if, 'pre_search', self.request, self): super().search(), 'post_search', self.request, self) self.result_container.close() return self.result_container