From 937165853185ca16b0da6f72bc42bd1487ea0dcb Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Mon, 13 Oct 2025 09:28:42 +0200 Subject: [mod] typification of SearXNG: add new result type File This PR adds a new result type: File Python class: searx/result_types/file.py Jinja template: searx/templates/simple/result_templates/file.html CSS (less) client/simple/src/less/result_types/file.less Class 'File' (singular) replaces template 'files.html' (plural). The renaming was carried out because there is only one file (singular) in a result. Not to be confused with the category 'files' where in multiple results can exist. As mentioned in issue [1], the class '.category-files' was removed from the CSS and the stylesheet was adopted in result_types/file.less (there based on the templates and no longer based on the category). [1] https://github.com/searxng/searxng/issues/5198 Signed-off-by: Markus Heiser --- searx/result_types/__init__.py | 3 ++ searx/result_types/_base.py | 23 +++++++---- searx/result_types/file.py | 94 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 searx/result_types/file.py (limited to 'searx/result_types') diff --git a/searx/result_types/__init__.py b/searx/result_types/__init__.py index a1976c10f..4ae2de816 100644 --- a/searx/result_types/__init__.py +++ b/searx/result_types/__init__.py @@ -23,6 +23,7 @@ __all__ = [ "WeatherAnswer", "Code", "Paper", + "File", ] import typing as t @@ -33,6 +34,7 @@ from .answer import AnswerSet, Answer, Translations, WeatherAnswer from .keyvalue import KeyValue from .code import Code from .paper import Paper +from .file import File class ResultList(list[Result | LegacyResult], abc.ABC): @@ -47,6 +49,7 @@ class ResultList(list[Result | LegacyResult], abc.ABC): KeyValue = KeyValue Code = Code Paper = Paper + File = File MainResult = MainResult Result = Result Translations = Translations diff --git a/searx/result_types/_base.py b/searx/result_types/_base.py index e97894b75..ffcf7f143 100644 --- a/searx/result_types/_base.py +++ b/searx/result_types/_base.py @@ -27,7 +27,6 @@ import typing as t import re import urllib.parse import warnings -import time import datetime from collections.abc import Callable @@ -236,13 +235,6 @@ class Result(msgspec.Struct, kw_only=True): url: str | None = None """A link related to this *result*""" - template: str = "default.html" - """Name of the template used to render the result. - - By default :origin:`result_templates/default.html - ` is used. - """ - engine: str | None = "" """Name of the engine *this* result comes from. In case of *plugins* a prefix ``plugin:`` is set, in case of *answerer* prefix ``answerer:`` is @@ -350,6 +342,13 @@ class Result(msgspec.Struct, kw_only=True): class MainResult(Result): # pylint: disable=missing-class-docstring """Base class of all result types displayed in :ref:`area main results`.""" + template: str = "default.html" + """Name of the template used to render the result. + + By default :origin:`result_templates/default.html + ` is used. + """ + title: str = "" """Link title of the result item.""" @@ -359,6 +358,12 @@ class MainResult(Result): # pylint: disable=missing-class-docstring img_src: str = "" """URL of a image that is displayed in the result item.""" + iframe_src: str = "" + """URL of an embedded ``