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

Public Member Functions

None __init__ (self, "PluginCfg" plg_cfg)
 
EngineResults post_search (self, "SXNG_Request" request, "SearchWithPlugins" search)
 
- Public Member Functions inherited from searx.plugins._core.Plugin
None __init__ (self, PluginCfg plg_cfg)
 
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)
 

Public Attributes

 info
 

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

Convert between units.  The result is displayed in area for the
"answers".

Definition at line 37 of file unit_converter.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 44 of file unit_converter.py.

44 def __init__(self, plg_cfg: "PluginCfg") -> None:
45 super().__init__(plg_cfg)
46
47 self.info = PluginInfo(
48 id=self.id,
49 name=gettext("Unit converter plugin"),
50 description=gettext("Convert between units"),
51 preference_section="general",
52 )
53

References __init__().

Referenced by __init__().

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

Member Function Documentation

◆ post_search()

EngineResults searx.plugins.unit_converter.SXNGPlugin.post_search ( self,
"SXNG_Request" request,
"SearchWithPlugins" search )
Runs AFTER the search request.  Can return a list of
:py:obj:`Result <searx.result_types._base.Result>` objects to be added to the
final result list.

Reimplemented from searx.plugins._core.Plugin.

Definition at line 54 of file unit_converter.py.

54 def post_search(self, request: "SXNG_Request", search: "SearchWithPlugins") -> EngineResults:
55 results = EngineResults()
56
57 # only convert between units on the first page
58 if search.search_query.pageno > 1:
59 return results
60
61 query = search.search_query.query
62 query_parts = query.split(" ")
63
64 if len(query_parts) < 3:
65 return results
66
67 for query_part in query_parts:
68 for keyword in CONVERT_KEYWORDS:
69 if query_part == keyword:
70 from_query, to_query = query.split(keyword, 1)
71 target_val = _parse_text_and_convert(from_query.strip(), to_query.strip())
72 if target_val:
73 results.add(results.types.Answer(answer=target_val))
74
75 return results
76
77
78# inspired from https://stackoverflow.com/a/42475086

References searx.plugins.unit_converter._parse_text_and_convert().

+ Here is the call graph for this function:

Member Data Documentation

◆ info

searx.plugins.unit_converter.SXNGPlugin.info
Initial value:
= PluginInfo(
id=self.id,
name=gettext("Unit converter plugin"),
description=gettext("Convert between units"),
preference_section="general",
)

Definition at line 47 of file unit_converter.py.


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