.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.plugins._core.Plugin Class Reference
+ Inheritance diagram for searx.plugins._core.Plugin:
+ Collaboration diagram for searx.plugins._core.Plugin:

Public Member Functions

None __init__ (self)
 
int __hash__ (self)
 
 __eq__ (self, other)
 
bool init (self, flask.Flask app)
 
bool pre_search (self, SXNG_Request request, "SearchWithPlugins" search)
 
bool on_result (self, SXNG_Request request, "SearchWithPlugins" search, Result result)
 
None|typing.Sequence[Resultpost_search (self, SXNG_Request request, "SearchWithPlugins" search)
 

Static Public Attributes

typing id .ClassVar[str]
 
typing default_on .ClassVar[bool]
 
list keywords = []
 
logging log .Logger
 

Detailed Description

Abstract base class of all Plugins.

Definition at line 72 of file _core.py.

Constructor & Destructor Documentation

◆ __init__()

None searx.plugins._core.Plugin.__init__ ( self)

Definition at line 94 of file _core.py.

94 def __init__(self) -> None:
95 super().__init__()
96
97 for attr in ["id", "default_on"]:
98 if getattr(self, attr, None) is None:
99 raise NotImplementedError(f"plugin {self} is missing attribute {attr}")
100
101 if not self.id:
102 self.id = f"{self.__class__.__module__}.{self.__class__.__name__}"
103 if not getattr(self, "log", None):
104 self.log = log.getChild(self.id)
105

References __init__(), id, and log.

Referenced by __init__().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Function Documentation

◆ __eq__()

searx.plugins._core.Plugin.__eq__ ( self,
other )
py:obj:`Plugin` objects are equal if the hash values of the two
objects are equal.

Definition at line 114 of file _core.py.

114 def __eq__(self, other):
115 """py:obj:`Plugin` objects are equal if the hash values of the two
116 objects are equal."""
117
118 return hash(self) == hash(other)
119

◆ __hash__()

int searx.plugins._core.Plugin.__hash__ ( self)
The hash value is used in :py:obj:`set`, for example, when an object
is added to the set.  The hash value is also used in other contexts,
e.g. when checking for equality to identify identical plugins from
different sources (name collisions).

Definition at line 106 of file _core.py.

106 def __hash__(self) -> int:
107 """The hash value is used in :py:obj:`set`, for example, when an object
108 is added to the set. The hash value is also used in other contexts,
109 e.g. when checking for equality to identify identical plugins from
110 different sources (name collisions)."""
111
112 return id(self)
113

References id.

◆ init()

bool searx.plugins._core.Plugin.init ( self,
flask.Flask app )
Initialization of the plugin, the return value decides whether this
plugin is active or not.  Initialization only takes place once, at the
time the WEB application is set up.  The base methode always returns
``True``, the methode can be overwritten in the inheritances,

- ``True`` plugin is active
- ``False`` plugin is inactive

Reimplemented in searx.plugins._core.ModulePlugin.

Definition at line 120 of file _core.py.

120 def init(self, app: flask.Flask) -> bool: # pylint: disable=unused-argument
121 """Initialization of the plugin, the return value decides whether this
122 plugin is active or not. Initialization only takes place once, at the
123 time the WEB application is set up. The base methode always returns
124 ``True``, the methode can be overwritten in the inheritances,
125
126 - ``True`` plugin is active
127 - ``False`` plugin is inactive
128 """
129 return True
130

Referenced by searx.sqlitedb.SQLiteAppl.connect().

+ Here is the caller graph for this function:

◆ on_result()

bool searx.plugins._core.Plugin.on_result ( self,
SXNG_Request request,
"SearchWithPlugins" search,
Result result )
Runs for each result of each engine and returns a boolean:

- ``True`` to keep the result
- ``False`` to remove the result from the result list

The ``result`` can be modified to the needs.

.. hint::

   If :py:obj:`Result.url` is modified, :py:obj:`Result.parsed_url` must
   be changed accordingly:

   .. code:: python

      result["parsed_url"] = urlparse(result["url"])

Reimplemented in searx.plugins._core.ModulePlugin.

Definition at line 140 of file _core.py.

140 def on_result(self, request: SXNG_Request, search: "SearchWithPlugins", result: Result) -> bool:
141 """Runs for each result of each engine and returns a boolean:
142
143 - ``True`` to keep the result
144 - ``False`` to remove the result from the result list
145
146 The ``result`` can be modified to the needs.
147
148 .. hint::
149
150 If :py:obj:`Result.url` is modified, :py:obj:`Result.parsed_url` must
151 be changed accordingly:
152
153 .. code:: python
154
155 result["parsed_url"] = urlparse(result["url"])
156 """
157 return True
158

◆ post_search()

None | typing.Sequence[Result] searx.plugins._core.Plugin.post_search ( self,
SXNG_Request request,
"SearchWithPlugins" search )
Runs AFTER the search request.  Can return a list of :py:obj:`Result`
objects to be added to the final result list.

Reimplemented in searx.plugins._core.ModulePlugin, searx.plugins.hash_plugin.SXNGPlugin, and searx.plugins.self_info.SXNGPlugin.

Definition at line 159 of file _core.py.

159 def post_search(self, request: SXNG_Request, search: "SearchWithPlugins") -> None | typing.Sequence[Result]:
160 """Runs AFTER the search request. Can return a list of :py:obj:`Result`
161 objects to be added to the final result list."""
162 return
163
164

◆ pre_search()

bool searx.plugins._core.Plugin.pre_search ( self,
SXNG_Request request,
"SearchWithPlugins" search )
Runs BEFORE the search request and returns a boolean:

- ``True`` to continue the search
- ``False`` to stop the search

Reimplemented in searx.plugins._core.ModulePlugin.

Definition at line 132 of file _core.py.

132 def pre_search(self, request: SXNG_Request, search: "SearchWithPlugins") -> bool:
133 """Runs BEFORE the search request and returns a boolean:
134
135 - ``True`` to continue the search
136 - ``False`` to stop the search
137 """
138 return True
139

Member Data Documentation

◆ default_on

typing searx.plugins._core.Plugin.default_on .ClassVar[bool]
static

Definition at line 78 of file _core.py.

◆ id

typing searx.plugins._core.Plugin.id .ClassVar[str]
static

Definition at line 75 of file _core.py.

Referenced by __hash__(), and __init__().

◆ keywords

list searx.plugins._core.Plugin.keywords = []
static

Definition at line 81 of file _core.py.

◆ log

logging searx.plugins._core.Plugin.log .Logger
static

Definition at line 87 of file _core.py.

Referenced by __init__().


The documentation for this class was generated from the following file: