unit_converter.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <title>Unit Converter &#8212; SearXNG Documentation (2025.4.30+fd33559cf)</title>
  8. <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=6625fa76" />
  9. <link rel="stylesheet" type="text/css" href="../../_static/searxng.css?v=52e4ff28" />
  10. <script src="../../_static/documentation_options.js?v=b12b0e12"></script>
  11. <script src="../../_static/doctools.js?v=9a2dae69"></script>
  12. <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
  13. <script data-project="searxng" data-version="2025.4.30+fd33559cf" src="../../_static/describe_version.js?v=fa7f30d0"></script>
  14. <link rel="index" title="Index" href="../../genindex.html" />
  15. <link rel="search" title="Search" href="../../search.html" />
  16. <link rel="next" title="Answerers" href="../answerers/index.html" />
  17. <link rel="prev" title="Tor check" href="tor_check.html" />
  18. </head><body>
  19. <div class="related" role="navigation" aria-label="Related">
  20. <h3>Navigation</h3>
  21. <ul>
  22. <li class="right" style="margin-right: 10px">
  23. <a href="../../genindex.html" title="General Index"
  24. accesskey="I">index</a></li>
  25. <li class="right" >
  26. <a href="../../py-modindex.html" title="Python Module Index"
  27. >modules</a> |</li>
  28. <li class="right" >
  29. <a href="../answerers/index.html" title="Answerers"
  30. accesskey="N">next</a> |</li>
  31. <li class="right" >
  32. <a href="tor_check.html" title="Tor check"
  33. accesskey="P">previous</a> |</li>
  34. <li class="nav-item nav-item-0"><a href="../../index.html">SearXNG Documentation (2025.4.30+fd33559cf)</a> &#187;</li>
  35. <li class="nav-item nav-item-1"><a href="../index.html" >Developer documentation</a> &#187;</li>
  36. <li class="nav-item nav-item-2"><a href="index.html" >Plugins</a> &#187;</li>
  37. <li class="nav-item nav-item-3"><a href="builtins.html" accesskey="U">Built-in Plugins</a> &#187;</li>
  38. <li class="nav-item nav-item-this"><a href="">Unit Converter</a></li>
  39. </ul>
  40. </div>
  41. <div class="document">
  42. <div class="documentwrapper">
  43. <div class="bodywrapper">
  44. <div class="body" role="main">
  45. <section id="module-searx.plugins.unit_converter">
  46. <span id="unit-converter"></span><span id="unit-converter-plugin"></span><h1>Unit Converter<a class="headerlink" href="#module-searx.plugins.unit_converter" title="Link to this heading">¶</a></h1>
  47. <p>A plugin for converting measured values from one unit to another unit (a
  48. unit converter).</p>
  49. <p>The plugin looks up the symbols (given in the query term) in a list of
  50. converters, each converter is one item in the list (compare
  51. <a class="reference internal" href="#searx.plugins.unit_converter.ADDITIONAL_UNITS" title="searx.plugins.unit_converter.ADDITIONAL_UNITS"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ADDITIONAL_UNITS</span></code></a>). If the symbols are ambiguous, the matching units
  52. of measurement are evaluated. The weighting in the evaluation results from the
  53. sorting of the <a class="reference internal" href="#searx.plugins.unit_converter.symbol_to_si" title="searx.plugins.unit_converter.symbol_to_si"><code class="xref py py-obj docutils literal notranslate"><span class="pre">list</span> <span class="pre">of</span> <span class="pre">unit</span> <span class="pre">converters</span></code></a>.</p>
  54. <dl class="py class">
  55. <dt class="sig sig-object py" id="searx.plugins.unit_converter.SXNGPlugin">
  56. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">searx.plugins.unit_converter.</span></span><span class="sig-name descname"><span class="pre">SXNGPlugin</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">plg_cfg</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="development.html#searx.plugins.PluginCfg" title="searx.plugins.PluginCfg"><span class="pre">PluginCfg</span></a></span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/searx/plugins/unit_converter.html#SXNGPlugin"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#searx.plugins.unit_converter.SXNGPlugin" title="Link to this definition">¶</a></dt>
  57. <dd><p>Convert between units. The result is displayed in area for the
  58. “answers”.</p>
  59. <dl class="py attribute">
  60. <dt class="sig sig-object py" id="searx.plugins.unit_converter.SXNGPlugin.id">
  61. <span class="sig-name descname"><span class="pre">id</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">'unit_converter'</span></em><a class="headerlink" href="#searx.plugins.unit_converter.SXNGPlugin.id" title="Link to this definition">¶</a></dt>
  62. <dd><p>The ID (suffix) in the HTML form.</p>
  63. </dd></dl>
  64. <dl class="py method">
  65. <dt class="sig sig-object py" id="searx.plugins.unit_converter.SXNGPlugin.post_search">
  66. <span class="sig-name descname"><span class="pre">post_search</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">request</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="../extended_types.html#searx.extended_types.SXNG_Request" title="searx.extended_types.SXNG_Request"><span class="pre">SXNG_Request</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">search</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="../../src/searx.search.html#searx.search.SearchWithPlugins" title="searx.search.SearchWithPlugins"><span class="pre">SearchWithPlugins</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="../engines/index.html#searx.result_types.EngineResults" title="searx.result_types.EngineResults"><span class="pre">EngineResults</span></a></span></span><a class="reference internal" href="../../_modules/searx/plugins/unit_converter.html#SXNGPlugin.post_search"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#searx.plugins.unit_converter.SXNGPlugin.post_search" title="Link to this definition">¶</a></dt>
  67. <dd><p>Runs AFTER the search request. Can return a list of
  68. <a class="reference internal" href="../result_types/base_result.html#searx.result_types._base.Result" title="searx.result_types._base.Result"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Result</span></code></a> objects to be added to the
  69. final result list.</p>
  70. </dd></dl>
  71. </dd></dl>
  72. <dl class="py data">
  73. <dt class="sig sig-object py" id="searx.plugins.unit_converter.ADDITIONAL_UNITS">
  74. <span class="sig-prename descclassname"><span class="pre">searx.plugins.unit_converter.</span></span><span class="sig-name descname"><span class="pre">ADDITIONAL_UNITS</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">[{'from_si':</span> <span class="pre">&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'si_name':</span> <span class="pre">'Q11579',</span> <span class="pre">'symbol':</span> <span class="pre">'°C',</span> <span class="pre">'to_si':</span> <span class="pre">&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;},</span> <span class="pre">{'from_si':</span> <span class="pre">&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'si_name':</span> <span class="pre">'Q11579',</span> <span class="pre">'symbol':</span> <span class="pre">'°F',</span> <span class="pre">'to_si':</span> <span class="pre">&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;}]</span></em><a class="headerlink" href="#searx.plugins.unit_converter.ADDITIONAL_UNITS" title="Link to this definition">¶</a></dt>
  75. <dd><p>Additional items to convert from a measure unit to a SI unit (vice versa).</p>
  76. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
  77. <span class="s2">&quot;si_name&quot;</span><span class="p">:</span> <span class="s2">&quot;Q11579&quot;</span><span class="p">,</span> <span class="c1"># Wikidata item ID of the SI unit (Kelvin)</span>
  78. <span class="s2">&quot;symbol&quot;</span><span class="p">:</span> <span class="s2">&quot;°C&quot;</span><span class="p">,</span> <span class="c1"># symbol of the measure unit</span>
  79. <span class="s2">&quot;to_si&quot;</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">val</span><span class="p">:</span> <span class="n">val</span> <span class="o">+</span> <span class="mf">273.15</span><span class="p">,</span> <span class="c1"># convert measure value (val) to SI unit</span>
  80. <span class="s2">&quot;from_si&quot;</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">val</span><span class="p">:</span> <span class="n">val</span> <span class="o">-</span> <span class="mf">273.15</span><span class="p">,</span> <span class="c1"># convert SI value (val) measure unit</span>
  81. <span class="p">},</span>
  82. <span class="p">{</span>
  83. <span class="s2">&quot;si_name&quot;</span><span class="p">:</span> <span class="s2">&quot;Q11573&quot;</span><span class="p">,</span>
  84. <span class="s2">&quot;symbol&quot;</span><span class="p">:</span> <span class="s2">&quot;mi&quot;</span><span class="p">,</span>
  85. <span class="s2">&quot;to_si&quot;</span><span class="p">:</span> <span class="mf">1609.344</span><span class="p">,</span> <span class="c1"># convert measure value (val) to SI unit</span>
  86. <span class="s2">&quot;from_si&quot;</span><span class="p">:</span> <span class="mi">1</span> <span class="o">/</span> <span class="mf">1609.344</span> <span class="c1"># convert SI value (val) measure unit</span>
  87. <span class="p">},</span>
  88. </pre></div>
  89. </div>
  90. <p>The values of <code class="docutils literal notranslate"><span class="pre">to_si</span></code> and <code class="docutils literal notranslate"><span class="pre">from_si</span></code> can be of <a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.13)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code></a> (a multiplier)
  91. or a <a class="reference external" href="https://docs.python.org/3/glossary.html#term-callable">callable</a> (val in / converted value returned).</p>
  92. </dd></dl>
  93. <dl class="py data">
  94. <dt class="sig sig-object py" id="searx.plugins.unit_converter.ALIAS_SYMBOLS">
  95. <span class="sig-prename descclassname"><span class="pre">searx.plugins.unit_converter.</span></span><span class="sig-name descname"><span class="pre">ALIAS_SYMBOLS</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">{'mi':</span> <span class="pre">('L',),</span> <span class="pre">'°C':</span> <span class="pre">('C',),</span> <span class="pre">'°F':</span> <span class="pre">('F',)}</span></em><a class="headerlink" href="#searx.plugins.unit_converter.ALIAS_SYMBOLS" title="Link to this definition">¶</a></dt>
  96. <dd><p>Alias symbols for known unit of measure symbols / by example:</p>
  97. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="s1">&#39;°C&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="o">...</span><span class="p">),</span> <span class="c1"># list of alias symbols for °C (Q69362731)</span>
  98. <span class="s1">&#39;°F&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;F&#39;</span><span class="p">,</span> <span class="o">...</span><span class="p">),</span> <span class="c1"># list of alias symbols for °F (Q99490479)</span>
  99. <span class="s1">&#39;mi&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;L&#39;</span><span class="p">,),</span> <span class="c1"># list of alias symbols for mi (Q253276)</span>
  100. </pre></div>
  101. </div>
  102. </dd></dl>
  103. <dl class="py function">
  104. <dt class="sig sig-object py" id="searx.plugins.unit_converter.symbol_to_si">
  105. <span class="sig-prename descclassname"><span class="pre">searx.plugins.unit_converter.</span></span><span class="sig-name descname"><span class="pre">symbol_to_si</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/searx/plugins/unit_converter.html#symbol_to_si"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#searx.plugins.unit_converter.symbol_to_si" title="Link to this definition">¶</a></dt>
  106. <dd><p>Generates a list of tuples, each tuple is a measure unit and the fields
  107. in the tuple are:</p>
  108. <ol class="arabic simple" start="0">
  109. <li><p>Symbol of the measure unit (e.g. ‘mi’ for measure unit ‘miles’ Q253276)</p></li>
  110. <li><p>SI name of the measure unit (e.g. Q11573 for SI unit ‘metre’)</p></li>
  111. <li><p>Factor to get SI value from measure unit (e.g. 1mi is equal to SI 1m
  112. multiplied by 1609.344)</p></li>
  113. <li><p>Factor to get measure value from from SI value (e.g. SI 100m is equal to
  114. 100mi divided by 1609.344)</p></li>
  115. </ol>
  116. <p>The returned list is sorted, the first items are created from
  117. <code class="docutils literal notranslate"><span class="pre">WIKIDATA_UNITS</span></code>, the second group of items is build from
  118. <a class="reference internal" href="#searx.plugins.unit_converter.ADDITIONAL_UNITS" title="searx.plugins.unit_converter.ADDITIONAL_UNITS"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ADDITIONAL_UNITS</span></code></a> and items created from <a class="reference internal" href="#searx.plugins.unit_converter.ALIAS_SYMBOLS" title="searx.plugins.unit_converter.ALIAS_SYMBOLS"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ALIAS_SYMBOLS</span></code></a>.</p>
  119. <p>If you search this list for a symbol, then a match with a symbol from
  120. Wikidata has the highest weighting (first hit in the list), followed by the
  121. symbols from the <a class="reference internal" href="#searx.plugins.unit_converter.ADDITIONAL_UNITS" title="searx.plugins.unit_converter.ADDITIONAL_UNITS"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ADDITIONAL_UNITS</span></code></a> and the lowest weighting is
  122. given to the symbols resulting from the aliases <a class="reference internal" href="#searx.plugins.unit_converter.ALIAS_SYMBOLS" title="searx.plugins.unit_converter.ALIAS_SYMBOLS"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ALIAS_SYMBOLS</span></code></a>.</p>
  123. </dd></dl>
  124. </section>
  125. <div class="clearer"></div>
  126. </div>
  127. </div>
  128. </div>
  129. <span id="sidebar-top"></span>
  130. <div class="sphinxsidebar" role="navigation" aria-label="Main">
  131. <div class="sphinxsidebarwrapper">
  132. <p class="logo"><a href="../../index.html">
  133. <img class="logo" src="../../_static/searxng-wordmark.svg" alt="Logo of SearXNG"/>
  134. </a></p>
  135. <h3><a href="../../index.html">Table of Contents</a></h3>
  136. <ul class="current">
  137. <li class="toctree-l1"><a class="reference internal" href="../../user/index.html">User information</a></li>
  138. <li class="toctree-l1"><a class="reference internal" href="../../own-instance.html">Why use a private instance?</a></li>
  139. <li class="toctree-l1"><a class="reference internal" href="../../admin/index.html">Administrator documentation</a></li>
  140. <li class="toctree-l1 current"><a class="reference internal" href="../index.html">Developer documentation</a><ul class="current">
  141. <li class="toctree-l2"><a class="reference internal" href="../quickstart.html">Development Quickstart</a></li>
  142. <li class="toctree-l2"><a class="reference internal" href="../rtm_asdf.html">Runtime Management</a></li>
  143. <li class="toctree-l2"><a class="reference internal" href="../contribution_guide.html">How to contribute</a></li>
  144. <li class="toctree-l2"><a class="reference internal" href="../extended_types.html">Extended Types</a></li>
  145. <li class="toctree-l2"><a class="reference internal" href="../engines/index.html">Engine Implementations</a></li>
  146. <li class="toctree-l2"><a class="reference internal" href="../result_types/index.html">Result Types</a></li>
  147. <li class="toctree-l2"><a class="reference internal" href="../templates.html">Simple Theme Templates</a></li>
  148. <li class="toctree-l2"><a class="reference internal" href="../search_api.html">Search API</a></li>
  149. <li class="toctree-l2 current"><a class="reference internal" href="index.html">Plugins</a><ul class="current">
  150. <li class="toctree-l3"><a class="reference internal" href="development.html">Plugin Development</a></li>
  151. <li class="toctree-l3 current"><a class="reference internal" href="builtins.html">Built-in Plugins</a><ul class="current">
  152. <li class="toctree-l4"><a class="reference internal" href="calculator.html">Calculator</a></li>
  153. <li class="toctree-l4"><a class="reference internal" href="hash_plugin.html">Hash Values</a></li>
  154. <li class="toctree-l4"><a class="reference internal" href="hostnames.html">Hostnames</a></li>
  155. <li class="toctree-l4"><a class="reference internal" href="self_info.html">Self-Info</a></li>
  156. <li class="toctree-l4"><a class="reference internal" href="tor_check.html">Tor check</a></li>
  157. <li class="toctree-l4 current"><a class="current reference internal" href="#">Unit Converter</a><ul>
  158. <li class="toctree-l5"><a class="reference internal" href="#searx.plugins.unit_converter.SXNGPlugin"><code class="docutils literal notranslate"><span class="pre">SXNGPlugin</span></code></a></li>
  159. <li class="toctree-l5"><a class="reference internal" href="#searx.plugins.unit_converter.ADDITIONAL_UNITS"><code class="docutils literal notranslate"><span class="pre">ADDITIONAL_UNITS</span></code></a></li>
  160. <li class="toctree-l5"><a class="reference internal" href="#searx.plugins.unit_converter.ALIAS_SYMBOLS"><code class="docutils literal notranslate"><span class="pre">ALIAS_SYMBOLS</span></code></a></li>
  161. <li class="toctree-l5"><a class="reference internal" href="#searx.plugins.unit_converter.symbol_to_si"><code class="docutils literal notranslate"><span class="pre">symbol_to_si()</span></code></a></li>
  162. </ul>
  163. </li>
  164. </ul>
  165. </li>
  166. </ul>
  167. </li>
  168. <li class="toctree-l2"><a class="reference internal" href="../answerers/index.html">Answerers</a></li>
  169. <li class="toctree-l2"><a class="reference internal" href="../translation.html">Translation</a></li>
  170. <li class="toctree-l2"><a class="reference internal" href="../lxcdev.html">Developing in Linux Containers</a></li>
  171. <li class="toctree-l2"><a class="reference internal" href="../makefile.html">Makefile &amp; <code class="docutils literal notranslate"><span class="pre">./manage</span></code></a></li>
  172. <li class="toctree-l2"><a class="reference internal" href="../reST.html">reST primer</a></li>
  173. <li class="toctree-l2"><a class="reference internal" href="../searxng_extra/index.html">Tooling box <code class="docutils literal notranslate"><span class="pre">searxng_extra</span></code></a></li>
  174. </ul>
  175. </li>
  176. <li class="toctree-l1"><a class="reference internal" href="../../utils/index.html">DevOps tooling box</a></li>
  177. <li class="toctree-l1"><a class="reference internal" href="../../src/index.html">Source-Code</a></li>
  178. </ul>
  179. <h3>Project Links</h3>
  180. <ul>
  181. <li><a href="https://github.com/searxng/searxng/tree/master">Source</a>
  182. <li><a href="https://github.com/searxng/searxng/wiki">Wiki</a>
  183. <li><a href="https://searx.space">Public instances</a>
  184. <li><a href="https://github.com/searxng/searxng/issues">Issue Tracker</a>
  185. </ul><h3>Navigation</h3>
  186. <ul>
  187. <li><a href="../../index.html">Overview</a>
  188. <ul>
  189. <li><a href="../index.html">Developer documentation</a>
  190. <ul>
  191. <li><a href="index.html">Plugins</a>
  192. <ul>
  193. <li><a href="builtins.html">Built-in Plugins</a>
  194. <ul>
  195. <li>Previous: <a href="tor_check.html" title="previous chapter">Tor check</a>
  196. <li>Next: <a href="../answerers/index.html" title="next chapter">Answerers</a></ul>
  197. </li></ul>
  198. </li></ul>
  199. </li>
  200. </ul>
  201. </li>
  202. </ul>
  203. <search id="searchbox" style="display: none" role="search">
  204. <h3 id="searchlabel">Quick search</h3>
  205. <div class="searchformwrapper">
  206. <form class="search" action="../../search.html" method="get">
  207. <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
  208. <input type="submit" value="Go" />
  209. </form>
  210. </div>
  211. </search>
  212. <script>document.getElementById('searchbox').style.display = "block"</script>
  213. <div role="note" aria-label="source link">
  214. <h3>This Page</h3>
  215. <ul class="this-page-menu">
  216. <li><a href="../../_sources/dev/plugins/unit_converter.rst.txt"
  217. rel="nofollow">Show Source</a></li>
  218. </ul>
  219. </div>
  220. </div>
  221. </div>
  222. <div class="clearer"></div>
  223. </div>
  224. <div class="footer" role="contentinfo">
  225. &#169; Copyright SearXNG team.
  226. </div>
  227. </body>
  228. </html>