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