__init__.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. from .online import OnlineProcessor
  3. from .offline import OfflineProcessor
  4. from .online_dictionary import OnlineDictionaryProcessor
  5. from .online_currency import OnlineCurrencyProcessor
  6. from .abstract import EngineProcessor
  7. from searx import logger
  8. import searx.engines as engines
  9. __all__ = ['EngineProcessor', 'OfflineProcessor', 'OnlineProcessor',
  10. 'OnlineDictionaryProcessor', 'OnlineCurrencyProcessor', 'processors']
  11. logger = logger.getChild('search.processors')
  12. processors = {}
  13. def get_processor_class(engine_type):
  14. for c in [OnlineProcessor, OfflineProcessor, OnlineDictionaryProcessor, OnlineCurrencyProcessor]:
  15. if c.engine_type == engine_type:
  16. return c
  17. return None
  18. def get_processor(engine, engine_name):
  19. engine_type = getattr(engine, 'engine_type', 'online')
  20. processor_class = get_processor_class(engine_type)
  21. if processor_class:
  22. return processor_class(engine, engine_name)
  23. else:
  24. return None
  25. def initialize(engine_list):
  26. engines.initialize_engines(engine_list)
  27. for engine_name, engine in engines.engines.items():
  28. processor = get_processor(engine, engine_name)
  29. if processor is None:
  30. logger.error('Error get processor for engine %s', engine_name)
  31. else:
  32. processors[engine_name] = processor