summaryrefslogtreecommitdiff
path: root/searx/result_types
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2025-01-28 16:51:07 +0100
committerMarkus Heiser <markus.heiser@darmarIT.de>2025-01-29 05:04:41 +0100
commitdf3344e5d5fdfd2425324d5e10e8c8e5104963b0 (patch)
treece9af594706b1f81eba7349b58b6f349fe4ffb87 /searx/result_types
parent906b9e7d4c87dcb7ded4ef1248e9569caf408cc7 (diff)
[fix] JSON & CSV format return error 500
For CSV and JSON output, the LegacyResult and the Result objects needs to be converted to a python dictionary. Closes: https://github.com/searxng/searxng/issues/4244 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/result_types')
-rw-r--r--searx/result_types/_base.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/searx/result_types/_base.py b/searx/result_types/_base.py
index 6d9a49943..66e31c7f2 100644
--- a/searx/result_types/_base.py
+++ b/searx/result_types/_base.py
@@ -110,6 +110,9 @@ class Result(msgspec.Struct, kw_only=True):
return iter(self.__struct_fields__)
+ def as_dict(self):
+ return {f: getattr(self, f) for f in self.__struct_fields__}
+
class LegacyResult(dict):
"""A wrapper around a legacy result item. The SearXNG core uses this class
@@ -130,10 +133,12 @@ class LegacyResult(dict):
UNSET = object()
WHITESPACE_REGEX = re.compile('( |\t|\n)+', re.M | re.U)
+ def as_dict(self):
+ return self
+
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
- self.__dict__ = self
# Init fields with defaults / compare with defaults of the fields in class Result
self.engine = self.get("engine", "")