.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.plugins.hostnames.SXNGPlugin Class Reference
Inheritance diagram for searx.plugins.hostnames.SXNGPlugin:
Collaboration diagram for searx.plugins.hostnames.SXNGPlugin:

Public Member Functions

None __init__ (self, "PluginCfg" plg_cfg)
bool on_result (self, "SXNG_Request" request, "SearchWithPlugins" search, "Result" result)
bool init (self, "flask.Flask" app)
Public Member Functions inherited from searx.plugins._core.Plugin
None __init__ (self, "PluginCfg" plg_cfg)
int __hash__ (self)
 __eq__ (self, typing.Any other)
bool pre_search (self, SXNG_Request request, "SearchWithPlugins" search)
None|Sequence[Resultpost_search (self, SXNG_Request request, "SearchWithPlugins" search)

Public Attributes

 info

Protected Member Functions

dict[re.Pattern, str]|set|None _load_regular_expressions (self, settings_key)

Additional Inherited Members

Static Public Attributes inherited from searx.plugins._core.Plugin
str id = ""
typing active .ClassVar[bool]
list keywords = []
logging log .Logger
str fqn = ""

Detailed Description

Rewrite hostnames, remove results or prioritize them.

Definition at line 110 of file hostnames.py.

Constructor & Destructor Documentation

◆ __init__()

None searx.plugins.hostnames.SXNGPlugin.__init__ ( self,
"PluginCfg" plg_cfg )

Definition at line 115 of file hostnames.py.

115 def __init__(self, plg_cfg: "PluginCfg") -> None:
116 super().__init__(plg_cfg)
117 self.info = PluginInfo(
118 id=self.id,
119 name=gettext("Hostnames plugin"),
120 description=gettext("Rewrite hostnames and remove or prioritize results based on the hostname"),
121 preference_section="general",
122 )
123

References __init__().

Referenced by __init__().

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

Member Function Documentation

◆ _load_regular_expressions()

dict[re.Pattern, str] | set | None searx.plugins.hostnames.SXNGPlugin._load_regular_expressions ( self,
settings_key )
protected

Definition at line 161 of file hostnames.py.

161 def _load_regular_expressions(self, settings_key) -> dict[re.Pattern, str] | set | None:
162 setting_value = settings.get(self.id, {}).get(settings_key)
163
164 if not setting_value:
165 return None
166
167 # load external file with configuration
168 if isinstance(setting_value, str):
169 setting_value = get_yaml_cfg(setting_value)
170
171 if isinstance(setting_value, list):
172 return {re.compile(r) for r in setting_value}
173
174 if isinstance(setting_value, dict):
175 return {re.compile(p): r for (p, r) in setting_value.items()}
176
177 return None
178
179

References searx.plugins._core.Plugin.id.

Referenced by init().

Here is the caller graph for this function:

◆ init()

bool searx.plugins.hostnames.SXNGPlugin.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 method always returns
``True``, the method can be overwritten in the inheritances,

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

Reimplemented from searx.plugins._core.Plugin.

Definition at line 147 of file hostnames.py.

147 def init(self, app: "flask.Flask") -> bool: # pylint: disable=unused-argument
148 global REPLACE, REMOVE, HIGH, LOW # pylint: disable=global-statement
149
150 if not settings.get(self.id):
151 # Remove plugin, if there isn't a "hostnames:" setting
152 return False
153
154 REPLACE = self._load_regular_expressions("replace") or {} # type: ignore
155 REMOVE = self._load_regular_expressions("remove") or set() # type: ignore
156 HIGH = self._load_regular_expressions("high_priority") or set() # type: ignore
157 LOW = self._load_regular_expressions("low_priority") or set() # type: ignore
158
159 return True
160

References _load_regular_expressions(), and searx.plugins._core.Plugin.id.

Referenced by searx.sqlitedb.SQLiteAppl.connect(), and searx.sqlitedb.SQLiteAppl.DB().

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

◆ on_result()

bool searx.plugins.hostnames.SXNGPlugin.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 <searx.result_types._base.Result.url>` is modified,
   :py:obj:`Result.parsed_url <searx.result_types._base.Result.parsed_url>` must
   be changed accordingly:

   .. code:: python

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

Reimplemented from searx.plugins._core.Plugin.

Definition at line 124 of file hostnames.py.

124 def on_result(self, request: "SXNG_Request", search: "SearchWithPlugins", result: "Result") -> bool:
125
126 for pattern in REMOVE:
127 if result.parsed_url and pattern.search(result.parsed_url.netloc):
128 # if the link (parsed_url) of the result match, then remove the
129 # result from the result list, in any other case, the result
130 # remains in the list / see final "return True" below.
131 # log.debug("FIXME: remove [url/parsed_url] %s %s", pattern.pattern, result.url)
132 return False
133
134 result.filter_urls(filter_url_field)
135
136 if isinstance(result, (MainResult, LegacyResult)):
137 for pattern in LOW:
138 if result.parsed_url and pattern.search(result.parsed_url.netloc):
139 result.priority = "low"
140
141 for pattern in HIGH:
142 if result.parsed_url and pattern.search(result.parsed_url.netloc):
143 result.priority = "high"
144
145 return True
146

Member Data Documentation

◆ info

searx.plugins.hostnames.SXNGPlugin.info
Initial value:
= PluginInfo(
id=self.id,
name=gettext("Hostnames plugin"),
description=gettext("Rewrite hostnames and remove or prioritize results based on the hostname"),
preference_section="general",
)

Definition at line 117 of file hostnames.py.


The documentation for this class was generated from the following file:
  • /home/andrew/Documents/code/public/searxng/searx/plugins/hostnames.py