.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
28
import
typing
as
t
29
import
abc
30
31
from
._base
import
Result, MainResult, LegacyResult
32
from
.answer
import
AnswerSet, Answer, Translations, WeatherAnswer
33
from
.keyvalue
import
KeyValue
34
from
.code
import
Code
35
from
.paper
import
Paper
36
37
38
class
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
67
class
EngineResults
(
ResultList
):
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
"""
searx.result_types.EngineResults
Definition
__init__.py:67
searx.result_types.ResultList.types
Definition
__init__.py:42
searx.result_types.ResultList
Definition
__init__.py:38
searx.result_types.ResultList.__init__
__init__(self)
Definition
__init__.py:58
searx.result_types.ResultList.add
add(self, Result|LegacyResult result)
Definition
__init__.py:62
searxng
searx
result_types
__init__.py
Generated on
for .oO SearXNG Developer Documentation Oo. by
1.14.0