mirror of
https://github.com/searxng/searxng.git
synced 2026-06-16 06:46:52 +02:00
[chore] complete and normalize the attributes of engine objects (#6258)
Drop outdated engine attributes: supported_languages, language_aliases Complete, normalize and document the type definitions for the engine-module and engine-class. For the ``engine.about`` section of the configuration, a type check is performed based on structure ``searx.enginelib.EngineAbout``. The property ``engine.about.language`` no longer exists; existing values have been migrated to ``engine.language``. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
committed by
Markus Heiser
parent
b3e08f2a44
commit
6c9dcd4242
+76
-63
@@ -41,7 +41,7 @@ if t.TYPE_CHECKING:
|
||||
from searx.enginelib.traits import EngineTraits
|
||||
from searx.extended_types import SXNG_Response
|
||||
from searx.result_types import EngineResults
|
||||
from searx.search.processors import OfflineParamTypes, OnlineParamTypes
|
||||
from searx.search.processors import OfflineParamTypes, OnlineParamTypes, ProcessorType
|
||||
|
||||
ENGINES_CACHE: ExpireCacheSQLite = ExpireCacheSQLite.build_cache(
|
||||
ExpireCacheCfg(
|
||||
@@ -180,7 +180,7 @@ class EngineCache:
|
||||
return ENGINES_CACHE.secret_hash(name=name)
|
||||
|
||||
|
||||
class EngineAbout(msgspec.Struct):
|
||||
class EngineAbout(msgspec.Struct, kw_only=True):
|
||||
"""Additional fields describing the engine.
|
||||
|
||||
.. code:: yaml
|
||||
@@ -213,12 +213,11 @@ class EngineAbout(msgspec.Struct):
|
||||
results: str = ""
|
||||
"""Data format of the source (online-engines: of the response)."""
|
||||
|
||||
language: str = ""
|
||||
"""If the engine supports only one language, this language is specified
|
||||
here (``en``, ``de``, ``"no"`` or ..); otherwise, the value remains empty.
|
||||
description: str = ""
|
||||
"""Brief description of the engine and where it gets its data from.
|
||||
|
||||
For the YAML configuration: think of the `YAML-Norway problem
|
||||
<https://ruuda.nl/2023/the-yaml-document-from-hell#the-norway-problem>`_
|
||||
This value should only be set as long as no description of the data source
|
||||
is available via a :py:obj:`EngineAbout.wikidata_id`.
|
||||
"""
|
||||
|
||||
|
||||
@@ -227,6 +226,8 @@ class Engine(abc.ABC): # pylint: disable=too-few-public-methods
|
||||
|
||||
Further documentation see :ref:`general engine configuration`.
|
||||
|
||||
The defaults are taken from :py:obj:`searx.engines.ENGINE_DEFAULT_ARGS`.
|
||||
|
||||
.. hint::
|
||||
|
||||
This class is currently never initialized and only used for type hinting.
|
||||
@@ -234,49 +235,27 @@ class Engine(abc.ABC): # pylint: disable=too-few-public-methods
|
||||
|
||||
logger: logging.Logger
|
||||
|
||||
# Common options in the engine module
|
||||
# Common options of the engine module
|
||||
|
||||
engine_type: str
|
||||
engine_type: "ProcessorType" = "online"
|
||||
"""Type of the engine (:ref:`searx.search.processors`)"""
|
||||
|
||||
paging: bool
|
||||
paging: bool = False
|
||||
"""Engine supports multiple pages."""
|
||||
|
||||
max_page: int = 0
|
||||
"""If the engine supports paging, then this is the value for the last page
|
||||
that is still supported. ``0`` means unlimited numbers of pages."""
|
||||
|
||||
time_range_support: bool
|
||||
time_range_support: bool = False
|
||||
"""Engine supports search time range."""
|
||||
|
||||
safesearch: bool
|
||||
safesearch: bool = False
|
||||
"""Engine supports SafeSearch"""
|
||||
|
||||
language_support: bool
|
||||
language_support: bool = False
|
||||
"""Engine supports languages (locales) search."""
|
||||
|
||||
language: str
|
||||
"""For an engine, when there is ``language: ...`` in the YAML settings the engine
|
||||
does support only this one language:
|
||||
|
||||
.. code:: yaml
|
||||
|
||||
- name: google french
|
||||
engine: google
|
||||
language: fr
|
||||
"""
|
||||
|
||||
region: str
|
||||
"""For an engine, when there is ``region: ...`` in the YAML settings the engine
|
||||
does support only this one region::
|
||||
|
||||
.. code:: yaml
|
||||
|
||||
- name: google belgium
|
||||
engine: google
|
||||
region: fr-BE
|
||||
"""
|
||||
|
||||
fetch_traits: "Callable[[EngineTraits, bool], None]"
|
||||
"""Function to to fetch engine's traits from origin."""
|
||||
|
||||
@@ -285,9 +264,6 @@ class Engine(abc.ABC): # pylint: disable=too-few-public-methods
|
||||
|
||||
# settings.yml
|
||||
|
||||
categories: list[str]
|
||||
"""Specifies to which :ref:`engine categories` the engine should be added."""
|
||||
|
||||
name: str
|
||||
"""Name that will be used across SearXNG to define this engine. In settings, on
|
||||
the result page .."""
|
||||
@@ -297,6 +273,43 @@ class Engine(abc.ABC): # pylint: disable=too-few-public-methods
|
||||
this search engine (file name from :origin:`searx/engines` without
|
||||
``.py``)."""
|
||||
|
||||
categories: list[str] = ["general"]
|
||||
"""Specifies to which :ref:`engine categories` the engine should be added."""
|
||||
|
||||
language: str = ""
|
||||
"""If the engine supports only one language, this language is specified here
|
||||
(``en``, ``de``, ``"no"`` or ..); otherwise, the value remains empty. For
|
||||
the YAML configuration: think of the `YAML-Norway problem
|
||||
<https://ruuda.nl/2023/the-yaml-document-from-hell#the-norway-problem>`_
|
||||
|
||||
.. code:: yaml
|
||||
|
||||
- name: google norway
|
||||
engine: google
|
||||
language: "no"
|
||||
|
||||
Depending on ``language_support``, this value has similar but also slightly
|
||||
different meanings.
|
||||
|
||||
- When ``language_support`` is **true**, the map of
|
||||
:py:obj:`traits.EngineTraits.languages` is reduced to the selected
|
||||
language
|
||||
|
||||
- When ``language_support`` is **false**, then the implementation of the
|
||||
engine only supports this one ``language``
|
||||
"""
|
||||
|
||||
region: str = ""
|
||||
"""For an engine, when there is ``region: ...`` in the YAML settings the engine
|
||||
does support only this one region::
|
||||
|
||||
.. code:: yaml
|
||||
|
||||
- name: google belgium
|
||||
engine: google
|
||||
region: fr-BE
|
||||
"""
|
||||
|
||||
enable_http: bool
|
||||
"""Enable HTTP (by default only HTTPS is enabled)."""
|
||||
|
||||
@@ -309,6 +322,31 @@ class Engine(abc.ABC): # pylint: disable=too-few-public-methods
|
||||
display_error_messages: bool
|
||||
"""Display error messages on the web UI."""
|
||||
|
||||
disabled: bool = False
|
||||
"""To disable by default the engine, but not deleting it. It will allow the
|
||||
user to manually activate it in the settings."""
|
||||
|
||||
inactive: bool = False
|
||||
"""Remove the engine from the settings (*disabled & removed*)."""
|
||||
|
||||
about: EngineAbout = EngineAbout()
|
||||
"""Additional fields describing the engine."""
|
||||
|
||||
using_tor_proxy: bool = False
|
||||
"""Using tor proxy (``true``) or not (``false``) for this engine."""
|
||||
|
||||
send_accept_language_header: bool = True
|
||||
"""When this option is activated (default), the language (locale) that is
|
||||
selected by the user is used to build and send a ``Accept-Language`` header
|
||||
in the request to the origin search engine."""
|
||||
|
||||
tokens: list[str] = []
|
||||
"""A list of secret tokens to make this engine *private*, more details see
|
||||
:ref:`private engines`."""
|
||||
|
||||
weight: float = 1.0
|
||||
"""Weighting of the results of this engine (:ref:`weight <settings engines>`)."""
|
||||
|
||||
proxies: dict[str, dict[str, str]]
|
||||
"""Set proxies for a specific engine (YAML):
|
||||
|
||||
@@ -319,31 +357,6 @@ class Engine(abc.ABC): # pylint: disable=too-few-public-methods
|
||||
https: socks5://proxy:port
|
||||
"""
|
||||
|
||||
disabled: bool
|
||||
"""To disable by default the engine, but not deleting it. It will allow the
|
||||
user to manually activate it in the settings."""
|
||||
|
||||
inactive: bool
|
||||
"""Remove the engine from the settings (*disabled & removed*)."""
|
||||
|
||||
about: EngineAbout
|
||||
"""Additional fields describing the engine."""
|
||||
|
||||
using_tor_proxy: bool
|
||||
"""Using tor proxy (``true``) or not (``false``) for this engine."""
|
||||
|
||||
send_accept_language_header: bool
|
||||
"""When this option is activated (default), the language (locale) that is
|
||||
selected by the user is used to build and send a ``Accept-Language`` header
|
||||
in the request to the origin search engine."""
|
||||
|
||||
tokens: list[str]
|
||||
"""A list of secret tokens to make this engine *private*, more details see
|
||||
:ref:`private engines`."""
|
||||
|
||||
weight: int
|
||||
"""Weighting of the results of this engine (:ref:`weight <settings engines>`)."""
|
||||
|
||||
def setup(self, engine_settings: dict[str, t.Any]) -> bool: # pylint: disable=unused-argument
|
||||
"""Dynamic setup of the engine settings.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user