Skip to content

SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.

[mod] typification of SearXNG: add new result type Image (#6142)

Markus Heiserc629dd4f3cca
diff --git a/client/simple/src/less/detail.less b/client/simple/src/less/result_types/image.less
similarity index 100%
rename from client/simple/src/less/detail.less
rename to client/simple/src/less/result_types/image.less
diff --git a/client/simple/src/less/style.less b/client/simple/src/less/style.less
index 32c2fdfa1..46ba5d491 100644
--- a/client/simple/src/less/style.less
+++ b/client/simple/src/less/style.less
@@ -7,7 +7,6 @@
@import "mixins.less";
@import "toolkit.less";
@import "autocomplete.less";
-@import "detail.less";
@import "animations.less";
@import "embedded.less";
@import "info.less";
@@ -1165,3 +1164,4 @@ pre code {
@import "result_types/code.less";
@import "result_types/paper.less";
@import "result_types/file.less";
+@import "result_types/image.less";
diff --git a/docs/dev/result_types/main/image.rst b/docs/dev/result_types/main/image.rst
new file mode 100644
index 000000000..809528ed2
--- /dev/null
+++ b/docs/dev/result_types/main/image.rst
@@ -0,0 +1,7 @@
+.. _result_types.image:
+
+=============
+Image Results
+=============
+
+.. automodule:: searx.result_types.image
diff --git a/docs/dev/result_types/main/mainresult.rst b/docs/dev/result_types/main/mainresult.rst
index dc5d3f005..0173cf837 100644
--- a/docs/dev/result_types/main/mainresult.rst
+++ b/docs/dev/result_types/main/mainresult.rst
@@ -1,4 +1,8 @@
.. _result_types.mainresult:
+============
+Main Results
+============
+
.. autoclass:: searx.result_types._base.MainResult
:members:
diff --git a/docs/dev/result_types/main_result.rst b/docs/dev/result_types/main_result.rst
index eff56740c..acf539a8a 100644
--- a/docs/dev/result_types/main_result.rst
+++ b/docs/dev/result_types/main_result.rst
@@ -18,13 +18,13 @@ following types have been implemented so far ..
main/code
main/paper
main/file
+ main/image
The :ref:`LegacyResult <LegacyResult>` is used internally for the results that
have not yet been typed. The templates can be used as orientation until the
final typing is complete.
- :ref:`template default` / :py:obj:`Result`
-- :ref:`template images`
- :ref:`template videos`
- :ref:`template torrent`
- :ref:`template map`
diff --git a/docs/dev/templates.rst b/docs/dev/templates.rst
index b43a0ea08..2b04e02de 100644
--- a/docs/dev/templates.rst
+++ b/docs/dev/templates.rst
@@ -129,53 +129,6 @@ audio_src : uri,
URL of an embedded ``<audio controls>``.
-.. _template images:
-
-``images.html``
----------------
-
-The images are displayed as small thumbnails in the main results list.
-
-title : :py:class:`str`
- Title of the image.
-
-thumbnail_src : :py:class:`str`
- URL of a preview of the image.
-
-resolution :py:class:`str`
- The resolution of the image (e.g. ``1920 x 1080`` pixel)
-
-
-Image labels
-~~~~~~~~~~~~
-
-Clicking on the preview opens a gallery view in which all further metadata for
-the image is displayed. Addition fields used in the :origin:`images.html
-<searx/templates/simple/result_templates/images.html>`:
-
-img_src : :py:class:`str`
- URL of the full size image.
-
-content: :py:class:`str`
- Description of the image.
-
-author: :py:class:`str`
- Name of the author of the image.
-
-img_format : :py:class:`str`
- The format of the image (e.g. ``png``).
-
-source : :py:class:`str`
- Source of the image.
-
-filesize: :py:class:`str`
- Size of bytes in :py:obj:`human readable <searx.humanize_bytes>` notation
- (e.g. ``MB`` for 1024 \* 1024 Bytes filesize).
-
-url : :py:class:`str`
- URL of the page from where the images comes from (source).
-
-
.. _template videos:
``videos.html``
diff --git a/searx/result_types/__init__.py b/searx/result_types/__init__.py
index 4ae2de816..e49ace224 100644
--- a/searx/result_types/__init__.py
+++ b/searx/result_types/__init__.py
@@ -35,6 +35,7 @@ from .keyvalue import KeyValue
from .code import Code
from .paper import Paper
from .file import File
+from .image import Image
class ResultList(list[Result | LegacyResult], abc.ABC):
@@ -50,6 +51,7 @@ class ResultList(list[Result | LegacyResult], abc.ABC):
Code = Code
Paper = Paper
File = File
+ Image = Image
MainResult = MainResult
Result = Result
Translations = Translations
diff --git a/searx/result_types/image.py b/searx/result_types/image.py
new file mode 100644
index 000000000..460264eb1
--- /dev/null
+++ b/searx/result_types/image.py
@@ -0,0 +1,44 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+"""Typification of the *image* results. Results of this type are rendered in
+the :origin:`images.html <searx/templates/simple/result_templates/images.html>`
+template.
+
+.. autoclass:: Image
+ :members:
+ :show-inheritance:
+
+"""
+
+__all__ = ["Image"]
+
+import typing as t
+
+
+from ._base import MainResult
+
+
+class Image(MainResult, kw_only=True):
+ """Result type suitable for displaying images.
+
+ The images are displayed as small thumbnails in the main results list.
+ Clicking on the preview opens a gallery view in which all further metadata
+ for the image is displayed."""
+
+ template: str = "images.html"
+
+ thumbnail_src: str = ""
+ """URL of a preview of the image."""
+
+ resolution: str = ""
+ """The resolution of the image (e.g. ``1920 x 1080`` pixel)"""
+
+ img_format: str = ""
+ """The format of the image (e.g. ``png``)."""
+
+ source: str = ""
+ """Source of the image."""
+
+ filesize: str = ""
+ """Size of bytes in :py:obj:`human readable <searx.humanize_bytes>` notation
+ (e.g. ``1MB`` for ``1024*1024`` Bytes filesize)."""