3"""Basic types for the typification of results.
5- :py:obj:`Result` base class
6- :py:obj:`LegacyResult` for internal use only
13.. autoclass:: LegacyResult
18from __future__
import annotations
29class Result(msgspec.Struct, kw_only=
True):
30 """Base class of all result types :ref:`result types`."""
32 url: str |
None =
None
33 """A link related to this *result*"""
35 template: str =
"default.html"
36 """Name of the template used to render the result.
38 By default :origin:`result_templates/default.html
39 <searx/templates/simple/result_templates/default.html>` is used.
42 engine: str |
None =
""
43 """Name of the engine *this* result comes from. In case of *plugins* a
44 prefix ``plugin:`` is set, in case of *answerer* prefix ``answerer:`` is
47 The field is optional and is initialized from the context if necessary.
50 parsed_url: urllib.parse.ParseResult |
None =
None
51 """:py:obj:`urllib.parse.ParseResult` of :py:obj:`Result.url`.
53 The field is optional and is initialized from the context if necessary.
57 """Normalize a result ..
59 - if field ``url`` is set and field ``parse_url`` is unset, init
60 ``parse_url`` from field ``url``. This method can be extended in the
77 """Generates a hash value that uniquely identifies the content of *this*
78 result. The method can be adapted in the inheritance to compare results
79 from different sources.
81 If two result objects are not identical but have the same content, their
82 hash values should also be identical.
84 The hash value is used in contexts, e.g. when checking for equality to
85 identify identical results from different sources (engines).
91 """py:obj:`Result` objects are equal if the hash values of the two
92 objects are equal. If needed, its recommended to overwrite
93 "py:obj:`Result.__hash__`."""
95 return hash(self) == hash(other)
101 return setattr(self, field_name, value)
106 raise KeyError(f
"{field_name}")
107 return getattr(self, field_name)
120 open_group: bool =
False
121 close_group: bool =
False
124 """Link title of the result item."""
127 """Extract or description of the result item"""
130 """URL of a image that is displayed in the result item."""
133 """URL of a thumbnail that is displayed in the result item."""
137 """A wrapper around a legacy result item. The SearXNG core uses this class
138 for untyped dictionaries / to be downward compatible.
140 This class is needed until we have implemented an :py:obj:`Result` class for
141 each result type and the old usages in the codebase have been fully
144 There is only one place where this class is used, in the
145 :py:obj:`searx.results.ResultContainer`.
149 Do not use this class in your own implementations!
153 WHITESPACE_REGEX = re.compile(
'( |\t|\n)+', re.M | re.U)
164 self.
template = self.get(
"template",
"default.html")
165 self.
url = self.get(
"url",
None)
175 f
"engine {self.engine} is using deprecated `dict` for answers"
176 f
" / use a class from searx.result_types.answer",
179 self.
template =
"answer/legacy.html"
184 return hash(self[
"answer"])
185 if not any(cls
in self
for cls
in [
"suggestion",
"correction",
"infobox",
"number_of_results",
"engine_data"]):
187 return hash(self.
url)
192 return hash(self) == hash(other)
196 return f
"LegacyResult: {super().__repr__()}"
200 if default == self.
UNSET and name
not in self:
201 raise AttributeError(f
"LegacyResult object has no field named: {name}")
__getattr__(self, str name, default=UNSET)
normalize_result_fields(self)
__setattr__(self, str name, val)
__init__(self, *args, **kwargs)
__setitem__(self, field_name, value)
__getitem__(self, field_name)
normalize_result_fields(self)