.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, other)
 
bool pre_search (self, SXNG_Request request, "SearchWithPlugins" search)
 
None|typing.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 114 of file hostnames.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 119 of file hostnames.py.

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

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 165 of file hostnames.py.

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

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 methode always returns
``True``, the methode can be overwritten in the inheritances,

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

Reimplemented from searx.plugins._core.Plugin.

Definition at line 151 of file hostnames.py.

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

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

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

+ 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 128 of file hostnames.py.

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

Member Data Documentation

◆ info

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

Definition at line 121 of file hostnames.py.


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