.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
14
15__all__ = [
16 "Result",
17 "MainResult",
18 "KeyValue",
19 "EngineResults",
20 "AnswerSet",
21 "Answer",
22 "Translations",
23 "WeatherAnswer",
24 "Code",
25 "Paper",
26]
27
28import typing as t
29import abc
30
31from ._base import Result, MainResult, LegacyResult
32from .answer import AnswerSet, Answer, Translations, WeatherAnswer
33from .keyvalue import KeyValue
34from .code import Code
35from .paper import Paper
36
37
38class ResultList(list[Result | LegacyResult], abc.ABC):
39 """Base class of all result lists (abstract)."""
40
41 @t.final
42 class types: # pylint: disable=invalid-name
43 """The collection of result types (which have already been
44 implemented)."""
45
46 Answer = Answer
47 KeyValue = KeyValue
48 Code = Code
49 Paper = Paper
50 MainResult = MainResult
51 Result = Result
52 Translations = Translations
53 WeatherAnswer = WeatherAnswer
54
55 # for backward compatibility
56 LegacyResult = LegacyResult
57
58 def __init__(self):
59 # pylint: disable=useless-parent-delegation
60 super().__init__()
61
62 def add(self, result: Result | LegacyResult):
63 """Add a :py:`Result` item to the result list."""
64 self.append(result)
65
66
68 """Result list that should be used by engine developers. For convenience,
69 engine developers don't need to import types / see :py:obj:`ResultList.types`.
70
71 .. code:: python
72
73 from searx.result_types import EngineResults
74 ...
75 def response(resp) -> EngineResults:
76 res = EngineResults()
77 ...
78 res.add( res.types.Answer(answer="lorem ipsum ..", url="https://example.org") )
79 ...
80 return res
81 """
add(self, Result|LegacyResult result)
Definition __init__.py:62