.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
__init__.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Typification of the result items generated by the *engines*, *answerers* and
3*plugins*.
4
5.. note::
6
7 We are at the beginning of typing the results. Further typing will follow,
8 but this is a very large task that we will only be able to implement
9 gradually. For more, please read :ref:`result types`.
10
11"""
12# pylint: disable=too-few-public-methods
13
14from __future__ import annotations
15
16__all__ = ["Result", "MainResult", "KeyValue", "EngineResults", "AnswerSet", "Answer", "Translations", "WeatherAnswer"]
17
18import abc
19
20from searx import enginelib
21
22from ._base import Result, MainResult, LegacyResult
23from .answer import AnswerSet, Answer, Translations, WeatherAnswer
24from .keyvalue import KeyValue
25
26
27class ResultList(list, abc.ABC):
28 """Base class of all result lists (abstract)."""
29
30 class types: # pylint: disable=invalid-name
31 """The collection of result types (which have already been implemented)."""
32
33 Answer = Answer
34 KeyValue = KeyValue
35 MainResult = MainResult
36 Result = Result
37 Translations = Translations
38 WeatherAnswer = WeatherAnswer
39
40 # for backward compatibility
41 LegacyResult = LegacyResult
42
43 def __init__(self):
44 # pylint: disable=useless-parent-delegation
45 super().__init__()
46
47 def add(self, result: Result | LegacyResult):
48 """Add a :py:`Result` item to the result list."""
49 self.append(result)
50
51
53 """Result list that should be used by engine developers. For convenience,
54 engine developers don't need to import types / see :py:obj:`ResultList.types`.
55
56 .. code:: python
57
58 from searx.result_types import EngineResults
59 ...
60 def response(resp) -> EngineResults:
61 res = EngineResults()
62 ...
63 res.add( res.types.Answer(answer="lorem ipsum ..", url="https://example.org") )
64 ...
65 return res
66 """
add(self, Result|LegacyResult result)
Definition __init__.py:47