.oO SearXNG Developer Documentation Oo.
All Classes Namespaces Files Functions Variables Pages
__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"]
17
18import abc
19
20from searx import enginelib
21
22from ._base import Result, MainResult, LegacyResult
23from .answer import AnswerSet, Answer, Translations
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
39 # for backward compatibility
40 LegacyResult = LegacyResult
41
42 def __init__(self):
43 # pylint: disable=useless-parent-delegation
44 super().__init__()
45
46 def add(self, result: Result | LegacyResult):
47 """Add a :py:`Result` item to the result list."""
48 self.append(result)
49
50
52 """Result list that should be used by engine developers. For convenience,
53 engine developers don't need to import types / see :py:obj:`ResultList.types`.
54
55 .. code:: python
56
57 from searx.result_types import EngineResults
58 ...
59 def response(resp) -> EngineResults:
60 res = EngineResults()
61 ...
62 res.add( res.types.Answer(answer="lorem ipsum ..", url="https://example.org") )
63 ...
64 return res
65 """
add(self, Result|LegacyResult result)
Definition __init__.py:46