diff options
Diffstat (limited to '_modules/searx/search/processors')
-rw-r--r-- | _modules/searx/search/processors/abstract.html | 311 | ||||
-rw-r--r-- | _modules/searx/search/processors/offline.html | 137 | ||||
-rw-r--r-- | _modules/searx/search/processors/online.html | 350 | ||||
-rw-r--r-- | _modules/searx/search/processors/online_currency.html | 187 | ||||
-rw-r--r-- | _modules/searx/search/processors/online_dictionary.html | 174 | ||||
-rw-r--r-- | _modules/searx/search/processors/online_url_search.html | 159 |
6 files changed, 1318 insertions, 0 deletions
diff --git a/_modules/searx/search/processors/abstract.html b/_modules/searx/search/processors/abstract.html new file mode 100644 index 000000000..c25785a8f --- /dev/null +++ b/_modules/searx/search/processors/abstract.html @@ -0,0 +1,311 @@ +<!DOCTYPE html> + +<html lang="en" data-content_root="../../../../"> + <head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>searx.search.processors.abstract — SearXNG Documentation (2025.1.6+6dab7fe78)</title> + <link rel="stylesheet" type="text/css" href="../../../../_static/pygments.css?v=4f649999" /> + <link rel="stylesheet" type="text/css" href="../../../../_static/searxng.css?v=52e4ff28" /> + <script src="../../../../_static/documentation_options.js?v=ef740023"></script> + <script src="../../../../_static/doctools.js?v=9a2dae69"></script> + <script src="../../../../_static/sphinx_highlight.js?v=dc90522c"></script> + <script data-project="searxng" data-version="2025.1.6+6dab7fe78" src="../../../../_static/describe_version.js?v=fa7f30d0"></script> + <link rel="index" title="Index" href="../../../../genindex.html" /> + <link rel="search" title="Search" href="../../../../search.html" /> + </head><body> + <div class="related" role="navigation" aria-label="Related"> + <h3>Navigation</h3> + <ul> + <li class="right" style="margin-right: 10px"> + <a href="../../../../genindex.html" title="General Index" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../../../py-modindex.html" title="Python Module Index" + >modules</a> |</li> + <li class="nav-item nav-item-0"><a href="../../../../index.html">SearXNG Documentation (2025.1.6+6dab7fe78)</a> »</li> + <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> »</li> + <li class="nav-item nav-item-2"><a href="../../search.html" accesskey="U">searx.search</a> »</li> + <li class="nav-item nav-item-this"><a href="">searx.search.processors.abstract</a></li> + </ul> + </div> + + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body" role="main"> + + <h1>Source code for searx.search.processors.abstract</h1><div class="highlight"><pre> +<span></span><span class="c1"># SPDX-License-Identifier: AGPL-3.0-or-later</span> +<span class="sd">"""Abstract base classes for engine request processors.</span> + +<span class="sd">"""</span> + +<span class="kn">import</span> <span class="nn">threading</span> +<span class="kn">from</span> <span class="nn">abc</span> <span class="kn">import</span> <span class="n">abstractmethod</span><span class="p">,</span> <span class="n">ABC</span> +<span class="kn">from</span> <span class="nn">timeit</span> <span class="kn">import</span> <span class="n">default_timer</span> +<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Dict</span><span class="p">,</span> <span class="n">Union</span> + +<span class="kn">from</span> <span class="nn">searx</span> <span class="kn">import</span> <span class="n">settings</span><span class="p">,</span> <span class="n">logger</span> +<span class="kn">from</span> <span class="nn">searx.engines</span> <span class="kn">import</span> <span class="n">engines</span> +<span class="kn">from</span> <span class="nn">searx.network</span> <span class="kn">import</span> <span class="n">get_time_for_thread</span><span class="p">,</span> <span class="n">get_network</span> +<span class="kn">from</span> <span class="nn">searx.metrics</span> <span class="kn">import</span> <span class="n">histogram_observe</span><span class="p">,</span> <span class="n">counter_inc</span><span class="p">,</span> <span class="n">count_exception</span><span class="p">,</span> <span class="n">count_error</span> +<span class="kn">from</span> <span class="nn">searx.exceptions</span> <span class="kn">import</span> <span class="n">SearxEngineAccessDeniedException</span><span class="p">,</span> <span class="n">SearxEngineResponseException</span> +<span class="kn">from</span> <span class="nn">searx.utils</span> <span class="kn">import</span> <span class="n">get_engine_from_settings</span> + +<span class="n">logger</span> <span class="o">=</span> <span class="n">logger</span><span class="o">.</span><span class="n">getChild</span><span class="p">(</span><span class="s1">'searx.search.processor'</span><span class="p">)</span> +<span class="n">SUSPENDED_STATUS</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">str</span><span class="p">],</span> <span class="s1">'SuspendedStatus'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> + + +<div class="viewcode-block" id="SuspendedStatus"> +<a class="viewcode-back" href="../../../../src/searx.search.processors.html#searx.search.processors.abstract.SuspendedStatus">[docs]</a> +<span class="k">class</span> <span class="nc">SuspendedStatus</span><span class="p">:</span> +<span class="w"> </span><span class="sd">"""Class to handle suspend state."""</span> + + <span class="vm">__slots__</span> <span class="o">=</span> <span class="s1">'suspend_end_time'</span><span class="p">,</span> <span class="s1">'suspend_reason'</span><span class="p">,</span> <span class="s1">'continuous_errors'</span><span class="p">,</span> <span class="s1">'lock'</span> + + <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="bp">self</span><span class="o">.</span><span class="n">lock</span> <span class="o">=</span> <span class="n">threading</span><span class="o">.</span><span class="n">Lock</span><span class="p">()</span> + <span class="bp">self</span><span class="o">.</span><span class="n">continuous_errors</span> <span class="o">=</span> <span class="mi">0</span> + <span class="bp">self</span><span class="o">.</span><span class="n">suspend_end_time</span> <span class="o">=</span> <span class="mi">0</span> + <span class="bp">self</span><span class="o">.</span><span class="n">suspend_reason</span> <span class="o">=</span> <span class="kc">None</span> + + <span class="nd">@property</span> + <span class="k">def</span> <span class="nf">is_suspended</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">suspend_end_time</span> <span class="o">>=</span> <span class="n">default_timer</span><span class="p">()</span> + + <span class="k">def</span> <span class="nf">suspend</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">suspended_time</span><span class="p">,</span> <span class="n">suspend_reason</span><span class="p">):</span> + <span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span> + <span class="c1"># update continuous_errors / suspend_end_time</span> + <span class="bp">self</span><span class="o">.</span><span class="n">continuous_errors</span> <span class="o">+=</span> <span class="mi">1</span> + <span class="k">if</span> <span class="n">suspended_time</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> + <span class="n">suspended_time</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span> + <span class="n">settings</span><span class="p">[</span><span class="s1">'search'</span><span class="p">][</span><span class="s1">'max_ban_time_on_fail'</span><span class="p">],</span> + <span class="bp">self</span><span class="o">.</span><span class="n">continuous_errors</span> <span class="o">*</span> <span class="n">settings</span><span class="p">[</span><span class="s1">'search'</span><span class="p">][</span><span class="s1">'ban_time_on_fail'</span><span class="p">],</span> + <span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">suspend_end_time</span> <span class="o">=</span> <span class="n">default_timer</span><span class="p">()</span> <span class="o">+</span> <span class="n">suspended_time</span> + <span class="bp">self</span><span class="o">.</span><span class="n">suspend_reason</span> <span class="o">=</span> <span class="n">suspend_reason</span> + <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">'Suspend for </span><span class="si">%i</span><span class="s1"> seconds'</span><span class="p">,</span> <span class="n">suspended_time</span><span class="p">)</span> + + <span class="k">def</span> <span class="nf">resume</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span> + <span class="c1"># reset the suspend variables</span> + <span class="bp">self</span><span class="o">.</span><span class="n">continuous_errors</span> <span class="o">=</span> <span class="mi">0</span> + <span class="bp">self</span><span class="o">.</span><span class="n">suspend_end_time</span> <span class="o">=</span> <span class="mi">0</span> + <span class="bp">self</span><span class="o">.</span><span class="n">suspend_reason</span> <span class="o">=</span> <span class="kc">None</span></div> + + + +<div class="viewcode-block" id="EngineProcessor"> +<a class="viewcode-back" href="../../../../src/searx.search.processors.html#searx.search.processors.abstract.EngineProcessor">[docs]</a> +<span class="k">class</span> <span class="nc">EngineProcessor</span><span class="p">(</span><span class="n">ABC</span><span class="p">):</span> +<span class="w"> </span><span class="sd">"""Base classes used for all types of request processors."""</span> + + <span class="vm">__slots__</span> <span class="o">=</span> <span class="s1">'engine'</span><span class="p">,</span> <span class="s1">'engine_name'</span><span class="p">,</span> <span class="s1">'lock'</span><span class="p">,</span> <span class="s1">'suspended_status'</span><span class="p">,</span> <span class="s1">'logger'</span> + + <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">engine</span><span class="p">,</span> <span class="n">engine_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span> + <span class="bp">self</span><span class="o">.</span><span class="n">engine</span> <span class="o">=</span> <span class="n">engine</span> + <span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span> <span class="o">=</span> <span class="n">engine_name</span> + <span class="bp">self</span><span class="o">.</span><span class="n">logger</span> <span class="o">=</span> <span class="n">engines</span><span class="p">[</span><span class="n">engine_name</span><span class="p">]</span><span class="o">.</span><span class="n">logger</span> + <span class="n">key</span> <span class="o">=</span> <span class="n">get_network</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">)</span> + <span class="n">key</span> <span class="o">=</span> <span class="nb">id</span><span class="p">(</span><span class="n">key</span><span class="p">)</span> <span class="k">if</span> <span class="n">key</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span> + <span class="bp">self</span><span class="o">.</span><span class="n">suspended_status</span> <span class="o">=</span> <span class="n">SUSPENDED_STATUS</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">SuspendedStatus</span><span class="p">())</span> + + <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="k">try</span><span class="p">:</span> + <span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="o">.</span><span class="n">init</span><span class="p">(</span><span class="n">get_engine_from_settings</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">))</span> + <span class="k">except</span> <span class="n">SearxEngineResponseException</span> <span class="k">as</span> <span class="n">exc</span><span class="p">:</span> + <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">'Fail to initialize // </span><span class="si">%s</span><span class="s1">'</span><span class="p">,</span> <span class="n">exc</span><span class="p">)</span> + <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span> <span class="c1"># pylint: disable=broad-except</span> + <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="s1">'Fail to initialize'</span><span class="p">)</span> + <span class="k">else</span><span class="p">:</span> + <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">'Initialized'</span><span class="p">)</span> + + <span class="nd">@property</span> + <span class="k">def</span> <span class="nf">has_initialize_function</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="k">return</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="p">,</span> <span class="s1">'init'</span><span class="p">)</span> + + <span class="k">def</span> <span class="nf">handle_exception</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">result_container</span><span class="p">,</span> <span class="n">exception_or_message</span><span class="p">,</span> <span class="n">suspend</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span> + <span class="c1"># update result_container</span> + <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">exception_or_message</span><span class="p">,</span> <span class="ne">BaseException</span><span class="p">):</span> + <span class="n">exception_class</span> <span class="o">=</span> <span class="n">exception_or_message</span><span class="o">.</span><span class="vm">__class__</span> + <span class="n">module_name</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">exception_class</span><span class="p">,</span> <span class="s1">'__module__'</span><span class="p">,</span> <span class="s1">'builtins'</span><span class="p">)</span> + <span class="n">module_name</span> <span class="o">=</span> <span class="s1">''</span> <span class="k">if</span> <span class="n">module_name</span> <span class="o">==</span> <span class="s1">'builtins'</span> <span class="k">else</span> <span class="n">module_name</span> <span class="o">+</span> <span class="s1">'.'</span> + <span class="n">error_message</span> <span class="o">=</span> <span class="n">module_name</span> <span class="o">+</span> <span class="n">exception_class</span><span class="o">.</span><span class="vm">__qualname__</span> + <span class="k">else</span><span class="p">:</span> + <span class="n">error_message</span> <span class="o">=</span> <span class="n">exception_or_message</span> + <span class="n">result_container</span><span class="o">.</span><span class="n">add_unresponsive_engine</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">,</span> <span class="n">error_message</span><span class="p">)</span> + <span class="c1"># metrics</span> + <span class="n">counter_inc</span><span class="p">(</span><span class="s1">'engine'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">,</span> <span class="s1">'search'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'error'</span><span class="p">)</span> + <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">exception_or_message</span><span class="p">,</span> <span class="ne">BaseException</span><span class="p">):</span> + <span class="n">count_exception</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">,</span> <span class="n">exception_or_message</span><span class="p">)</span> + <span class="k">else</span><span class="p">:</span> + <span class="n">count_error</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">,</span> <span class="n">exception_or_message</span><span class="p">)</span> + <span class="c1"># suspend the engine ?</span> + <span class="k">if</span> <span class="n">suspend</span><span class="p">:</span> + <span class="n">suspended_time</span> <span class="o">=</span> <span class="kc">None</span> + <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">exception_or_message</span><span class="p">,</span> <span class="n">SearxEngineAccessDeniedException</span><span class="p">):</span> + <span class="n">suspended_time</span> <span class="o">=</span> <span class="n">exception_or_message</span><span class="o">.</span><span class="n">suspended_time</span> + <span class="bp">self</span><span class="o">.</span><span class="n">suspended_status</span><span class="o">.</span><span class="n">suspend</span><span class="p">(</span><span class="n">suspended_time</span><span class="p">,</span> <span class="n">error_message</span><span class="p">)</span> <span class="c1"># pylint: disable=no-member</span> + + <span class="k">def</span> <span class="nf">_extend_container_basic</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">result_container</span><span class="p">,</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">search_results</span><span class="p">):</span> + <span class="c1"># update result_container</span> + <span class="n">result_container</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">,</span> <span class="n">search_results</span><span class="p">)</span> + <span class="n">engine_time</span> <span class="o">=</span> <span class="n">default_timer</span><span class="p">()</span> <span class="o">-</span> <span class="n">start_time</span> + <span class="n">page_load_time</span> <span class="o">=</span> <span class="n">get_time_for_thread</span><span class="p">()</span> + <span class="n">result_container</span><span class="o">.</span><span class="n">add_timing</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">,</span> <span class="n">engine_time</span><span class="p">,</span> <span class="n">page_load_time</span><span class="p">)</span> + <span class="c1"># metrics</span> + <span class="n">counter_inc</span><span class="p">(</span><span class="s1">'engine'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">,</span> <span class="s1">'search'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'successful'</span><span class="p">)</span> + <span class="n">histogram_observe</span><span class="p">(</span><span class="n">engine_time</span><span class="p">,</span> <span class="s1">'engine'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">,</span> <span class="s1">'time'</span><span class="p">,</span> <span class="s1">'total'</span><span class="p">)</span> + <span class="k">if</span> <span class="n">page_load_time</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> + <span class="n">histogram_observe</span><span class="p">(</span><span class="n">page_load_time</span><span class="p">,</span> <span class="s1">'engine'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">,</span> <span class="s1">'time'</span><span class="p">,</span> <span class="s1">'http'</span><span class="p">)</span> + + <span class="k">def</span> <span class="nf">extend_container</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">result_container</span><span class="p">,</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">search_results</span><span class="p">):</span> + <span class="k">if</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">threading</span><span class="o">.</span><span class="n">current_thread</span><span class="p">(),</span> <span class="s1">'_timeout'</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span> + <span class="c1"># the main thread is not waiting anymore</span> + <span class="bp">self</span><span class="o">.</span><span class="n">handle_exception</span><span class="p">(</span><span class="n">result_container</span><span class="p">,</span> <span class="s1">'timeout'</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> + <span class="k">else</span><span class="p">:</span> + <span class="c1"># check if the engine accepted the request</span> + <span class="k">if</span> <span class="n">search_results</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> + <span class="bp">self</span><span class="o">.</span><span class="n">_extend_container_basic</span><span class="p">(</span><span class="n">result_container</span><span class="p">,</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">search_results</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">suspended_status</span><span class="o">.</span><span class="n">resume</span><span class="p">()</span> + + <span class="k">def</span> <span class="nf">extend_container_if_suspended</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">result_container</span><span class="p">):</span> + <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">suspended_status</span><span class="o">.</span><span class="n">is_suspended</span><span class="p">:</span> + <span class="n">result_container</span><span class="o">.</span><span class="n">add_unresponsive_engine</span><span class="p">(</span> + <span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">suspended_status</span><span class="o">.</span><span class="n">suspend_reason</span><span class="p">,</span> <span class="n">suspended</span><span class="o">=</span><span class="kc">True</span> + <span class="p">)</span> + <span class="k">return</span> <span class="kc">True</span> + <span class="k">return</span> <span class="kc">False</span> + +<div class="viewcode-block" id="EngineProcessor.get_params"> +<a class="viewcode-back" href="../../../../src/searx.search.processors.html#searx.search.processors.abstract.EngineProcessor.get_params">[docs]</a> + <span class="k">def</span> <span class="nf">get_params</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search_query</span><span class="p">,</span> <span class="n">engine_category</span><span class="p">):</span> +<span class="w"> </span><span class="sd">"""Returns a set of (see :ref:`request params <engine request arguments>`) or</span> +<span class="sd"> ``None`` if request is not supported.</span> + +<span class="sd"> Not supported conditions (``None`` is returned):</span> + +<span class="sd"> - A page-number > 1 when engine does not support paging.</span> +<span class="sd"> - A time range when the engine does not support time range.</span> +<span class="sd"> """</span> + <span class="c1"># if paging is not supported, skip</span> + <span class="k">if</span> <span class="n">search_query</span><span class="o">.</span><span class="n">pageno</span> <span class="o">></span> <span class="mi">1</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="o">.</span><span class="n">paging</span><span class="p">:</span> + <span class="k">return</span> <span class="kc">None</span> + + <span class="c1"># if max page is reached, skip</span> + <span class="n">max_page</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="o">.</span><span class="n">max_page</span> <span class="ow">or</span> <span class="n">settings</span><span class="p">[</span><span class="s1">'search'</span><span class="p">][</span><span class="s1">'max_page'</span><span class="p">]</span> + <span class="k">if</span> <span class="n">max_page</span> <span class="ow">and</span> <span class="n">max_page</span> <span class="o"><</span> <span class="n">search_query</span><span class="o">.</span><span class="n">pageno</span><span class="p">:</span> + <span class="k">return</span> <span class="kc">None</span> + + <span class="c1"># if time_range is not supported, skip</span> + <span class="k">if</span> <span class="n">search_query</span><span class="o">.</span><span class="n">time_range</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="o">.</span><span class="n">time_range_support</span><span class="p">:</span> + <span class="k">return</span> <span class="kc">None</span> + + <span class="n">params</span> <span class="o">=</span> <span class="p">{}</span> + <span class="n">params</span><span class="p">[</span><span class="s1">'category'</span><span class="p">]</span> <span class="o">=</span> <span class="n">engine_category</span> + <span class="n">params</span><span class="p">[</span><span class="s1">'pageno'</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_query</span><span class="o">.</span><span class="n">pageno</span> + <span class="n">params</span><span class="p">[</span><span class="s1">'safesearch'</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_query</span><span class="o">.</span><span class="n">safesearch</span> + <span class="n">params</span><span class="p">[</span><span class="s1">'time_range'</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_query</span><span class="o">.</span><span class="n">time_range</span> + <span class="n">params</span><span class="p">[</span><span class="s1">'engine_data'</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_query</span><span class="o">.</span><span class="n">engine_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">,</span> <span class="p">{})</span> + <span class="n">params</span><span class="p">[</span><span class="s1">'searxng_locale'</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_query</span><span class="o">.</span><span class="n">lang</span> + + <span class="c1"># deprecated / vintage --> use params['searxng_locale']</span> + <span class="c1">#</span> + <span class="c1"># Conditions related to engine's traits are implemented in engine.traits</span> + <span class="c1"># module. Don't do 'locale' decisions here in the abstract layer of the</span> + <span class="c1"># search processor, just pass the value from user's choice unchanged to</span> + <span class="c1"># the engine request.</span> + + <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="p">,</span> <span class="s1">'language'</span><span class="p">)</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="o">.</span><span class="n">language</span><span class="p">:</span> + <span class="n">params</span><span class="p">[</span><span class="s1">'language'</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="o">.</span><span class="n">language</span> + <span class="k">else</span><span class="p">:</span> + <span class="n">params</span><span class="p">[</span><span class="s1">'language'</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_query</span><span class="o">.</span><span class="n">lang</span> + + <span class="k">return</span> <span class="n">params</span></div> + + + <span class="nd">@abstractmethod</span> + <span class="k">def</span> <span class="nf">search</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">query</span><span class="p">,</span> <span class="n">params</span><span class="p">,</span> <span class="n">result_container</span><span class="p">,</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">timeout_limit</span><span class="p">):</span> + <span class="k">pass</span> + + <span class="k">def</span> <span class="nf">get_tests</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="n">tests</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="p">,</span> <span class="s1">'tests'</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> + <span class="k">if</span> <span class="n">tests</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> + <span class="n">tests</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="p">,</span> <span class="s1">'additional_tests'</span><span class="p">,</span> <span class="p">{})</span> + <span class="n">tests</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_default_tests</span><span class="p">())</span> + <span class="k">return</span> <span class="n">tests</span> + + <span class="k">def</span> <span class="nf">get_default_tests</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="k">return</span> <span class="p">{}</span></div> + +</pre></div> + + <div class="clearer"></div> + </div> + </div> + </div> + <span id="sidebar-top"></span> + <div class="sphinxsidebar" role="navigation" aria-label="Main"> + <div class="sphinxsidebarwrapper"> + + + <p class="logo"><a href="../../../../index.html"> + <img class="logo" src="../../../../_static/searxng-wordmark.svg" alt="Logo of SearXNG"/> + </a></p> + + +<h3><a href="../../../../index.html">Table of Contents</a></h3> +<ul> +<li class="toctree-l1"><a class="reference internal" href="../../../../user/index.html">User information</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../own-instance.html">Why use a private instance?</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../admin/index.html">Administrator documentation</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../dev/index.html">Developer documentation</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../utils/index.html">DevOps tooling box</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../src/index.html">Source-Code</a></li> +</ul> + + <h3>Project Links</h3> + <ul> + <li><a href="https://github.com/searxng/searxng/tree/master">Source</a> + + <li><a href="https://github.com/searxng/searxng/wiki">Wiki</a> + + <li><a href="https://searx.space">Public instances</a> + + <li><a href="https://github.com/searxng/searxng/issues">Issue Tracker</a> + </ul><h3>Navigation</h3> +<ul> + <li><a href="../../../../index.html">Overview</a> + <ul> + <li><a href="../../../index.html">Module code</a> + <ul> + <li><a href="../../search.html">searx.search</a> + + + </ul> + </li></ul> + </li> + </ul> + </li> +</ul> +<search id="searchbox" style="display: none" role="search"> + <h3 id="searchlabel">Quick search</h3> + <div class="searchformwrapper"> + <form class="search" action="../../../../search.html" method="get"> + <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> + <input type="submit" value="Go" /> + </form> + </div> +</search> +<script>document.getElementById('searchbox').style.display = "block"</script> + </div> + </div> + <div class="clearer"></div> + </div> + <div class="footer" role="contentinfo"> + © Copyright SearXNG team. + </div> + </body> +</html>
\ No newline at end of file diff --git a/_modules/searx/search/processors/offline.html b/_modules/searx/search/processors/offline.html new file mode 100644 index 000000000..a08dc7cd7 --- /dev/null +++ b/_modules/searx/search/processors/offline.html @@ -0,0 +1,137 @@ +<!DOCTYPE html> + +<html lang="en" data-content_root="../../../../"> + <head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>searx.search.processors.offline — SearXNG Documentation (2025.1.6+6dab7fe78)</title> + <link rel="stylesheet" type="text/css" href="../../../../_static/pygments.css?v=4f649999" /> + <link rel="stylesheet" type="text/css" href="../../../../_static/searxng.css?v=52e4ff28" /> + <script src="../../../../_static/documentation_options.js?v=ef740023"></script> + <script src="../../../../_static/doctools.js?v=9a2dae69"></script> + <script src="../../../../_static/sphinx_highlight.js?v=dc90522c"></script> + <script data-project="searxng" data-version="2025.1.6+6dab7fe78" src="../../../../_static/describe_version.js?v=fa7f30d0"></script> + <link rel="index" title="Index" href="../../../../genindex.html" /> + <link rel="search" title="Search" href="../../../../search.html" /> + </head><body> + <div class="related" role="navigation" aria-label="Related"> + <h3>Navigation</h3> + <ul> + <li class="right" style="margin-right: 10px"> + <a href="../../../../genindex.html" title="General Index" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../../../py-modindex.html" title="Python Module Index" + >modules</a> |</li> + <li class="nav-item nav-item-0"><a href="../../../../index.html">SearXNG Documentation (2025.1.6+6dab7fe78)</a> »</li> + <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> »</li> + <li class="nav-item nav-item-2"><a href="../../search.html" accesskey="U">searx.search</a> »</li> + <li class="nav-item nav-item-this"><a href="">searx.search.processors.offline</a></li> + </ul> + </div> + + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body" role="main"> + + <h1>Source code for searx.search.processors.offline</h1><div class="highlight"><pre> +<span></span><span class="c1"># SPDX-License-Identifier: AGPL-3.0-or-later</span> +<span class="sd">"""Processors for engine-type: ``offline``</span> + +<span class="sd">"""</span> + +<span class="kn">from</span> <span class="nn">.abstract</span> <span class="kn">import</span> <span class="n">EngineProcessor</span> + + +<div class="viewcode-block" id="OfflineProcessor"> +<a class="viewcode-back" href="../../../../src/searx.search.processors.html#searx.search.processors.offline.OfflineProcessor">[docs]</a> +<span class="k">class</span> <span class="nc">OfflineProcessor</span><span class="p">(</span><span class="n">EngineProcessor</span><span class="p">):</span> +<span class="w"> </span><span class="sd">"""Processor class used by ``offline`` engines"""</span> + + <span class="n">engine_type</span> <span class="o">=</span> <span class="s1">'offline'</span> + + <span class="k">def</span> <span class="nf">_search_basic</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">query</span><span class="p">,</span> <span class="n">params</span><span class="p">):</span> + <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">query</span><span class="p">,</span> <span class="n">params</span><span class="p">)</span> + + <span class="k">def</span> <span class="nf">search</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">query</span><span class="p">,</span> <span class="n">params</span><span class="p">,</span> <span class="n">result_container</span><span class="p">,</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">timeout_limit</span><span class="p">):</span> + <span class="k">try</span><span class="p">:</span> + <span class="n">search_results</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_search_basic</span><span class="p">(</span><span class="n">query</span><span class="p">,</span> <span class="n">params</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">extend_container</span><span class="p">(</span><span class="n">result_container</span><span class="p">,</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">search_results</span><span class="p">)</span> + <span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> + <span class="c1"># do not record the error</span> + <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="s1">'engine </span><span class="si">{0}</span><span class="s1"> : invalid input : </span><span class="si">{1}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">,</span> <span class="n">e</span><span class="p">))</span> + <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> <span class="c1"># pylint: disable=broad-except</span> + <span class="bp">self</span><span class="o">.</span><span class="n">handle_exception</span><span class="p">(</span><span class="n">result_container</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="s1">'engine </span><span class="si">{0}</span><span class="s1"> : exception : </span><span class="si">{1}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">,</span> <span class="n">e</span><span class="p">))</span></div> + +</pre></div> + + <div class="clearer"></div> + </div> + </div> + </div> + <span id="sidebar-top"></span> + <div class="sphinxsidebar" role="navigation" aria-label="Main"> + <div class="sphinxsidebarwrapper"> + + + <p class="logo"><a href="../../../../index.html"> + <img class="logo" src="../../../../_static/searxng-wordmark.svg" alt="Logo of SearXNG"/> + </a></p> + + +<h3><a href="../../../../index.html">Table of Contents</a></h3> +<ul> +<li class="toctree-l1"><a class="reference internal" href="../../../../user/index.html">User information</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../own-instance.html">Why use a private instance?</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../admin/index.html">Administrator documentation</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../dev/index.html">Developer documentation</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../utils/index.html">DevOps tooling box</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../src/index.html">Source-Code</a></li> +</ul> + + <h3>Project Links</h3> + <ul> + <li><a href="https://github.com/searxng/searxng/tree/master">Source</a> + + <li><a href="https://github.com/searxng/searxng/wiki">Wiki</a> + + <li><a href="https://searx.space">Public instances</a> + + <li><a href="https://github.com/searxng/searxng/issues">Issue Tracker</a> + </ul><h3>Navigation</h3> +<ul> + <li><a href="../../../../index.html">Overview</a> + <ul> + <li><a href="../../../index.html">Module code</a> + <ul> + <li><a href="../../search.html">searx.search</a> + + + </ul> + </li></ul> + </li> + </ul> + </li> +</ul> +<search id="searchbox" style="display: none" role="search"> + <h3 id="searchlabel">Quick search</h3> + <div class="searchformwrapper"> + <form class="search" action="../../../../search.html" method="get"> + <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> + <input type="submit" value="Go" /> + </form> + </div> +</search> +<script>document.getElementById('searchbox').style.display = "block"</script> + </div> + </div> + <div class="clearer"></div> + </div> + <div class="footer" role="contentinfo"> + © Copyright SearXNG team. + </div> + </body> +</html>
\ No newline at end of file diff --git a/_modules/searx/search/processors/online.html b/_modules/searx/search/processors/online.html new file mode 100644 index 000000000..6278818af --- /dev/null +++ b/_modules/searx/search/processors/online.html @@ -0,0 +1,350 @@ +<!DOCTYPE html> + +<html lang="en" data-content_root="../../../../"> + <head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>searx.search.processors.online — SearXNG Documentation (2025.1.6+6dab7fe78)</title> + <link rel="stylesheet" type="text/css" href="../../../../_static/pygments.css?v=4f649999" /> + <link rel="stylesheet" type="text/css" href="../../../../_static/searxng.css?v=52e4ff28" /> + <script src="../../../../_static/documentation_options.js?v=ef740023"></script> + <script src="../../../../_static/doctools.js?v=9a2dae69"></script> + <script src="../../../../_static/sphinx_highlight.js?v=dc90522c"></script> + <script data-project="searxng" data-version="2025.1.6+6dab7fe78" src="../../../../_static/describe_version.js?v=fa7f30d0"></script> + <link rel="index" title="Index" href="../../../../genindex.html" /> + <link rel="search" title="Search" href="../../../../search.html" /> + </head><body> + <div class="related" role="navigation" aria-label="Related"> + <h3>Navigation</h3> + <ul> + <li class="right" style="margin-right: 10px"> + <a href="../../../../genindex.html" title="General Index" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../../../py-modindex.html" title="Python Module Index" + >modules</a> |</li> + <li class="nav-item nav-item-0"><a href="../../../../index.html">SearXNG Documentation (2025.1.6+6dab7fe78)</a> »</li> + <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> »</li> + <li class="nav-item nav-item-2"><a href="../../search.html" accesskey="U">searx.search</a> »</li> + <li class="nav-item nav-item-this"><a href="">searx.search.processors.online</a></li> + </ul> + </div> + + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body" role="main"> + + <h1>Source code for searx.search.processors.online</h1><div class="highlight"><pre> +<span></span><span class="c1"># SPDX-License-Identifier: AGPL-3.0-or-later</span> +<span class="sd">"""Processors for engine-type: ``online``</span> + +<span class="sd">"""</span> +<span class="c1"># pylint: disable=use-dict-literal</span> + +<span class="kn">from</span> <span class="nn">timeit</span> <span class="kn">import</span> <span class="n">default_timer</span> +<span class="kn">import</span> <span class="nn">asyncio</span> +<span class="kn">import</span> <span class="nn">ssl</span> +<span class="kn">import</span> <span class="nn">httpx</span> + +<span class="kn">import</span> <span class="nn">searx.network</span> +<span class="kn">from</span> <span class="nn">searx.utils</span> <span class="kn">import</span> <span class="n">gen_useragent</span> +<span class="kn">from</span> <span class="nn">searx.exceptions</span> <span class="kn">import</span> <span class="p">(</span> + <span class="n">SearxEngineAccessDeniedException</span><span class="p">,</span> + <span class="n">SearxEngineCaptchaException</span><span class="p">,</span> + <span class="n">SearxEngineTooManyRequestsException</span><span class="p">,</span> +<span class="p">)</span> +<span class="kn">from</span> <span class="nn">searx.metrics.error_recorder</span> <span class="kn">import</span> <span class="n">count_error</span> +<span class="kn">from</span> <span class="nn">.abstract</span> <span class="kn">import</span> <span class="n">EngineProcessor</span> + + +<div class="viewcode-block" id="default_request_params"> +<a class="viewcode-back" href="../../../../src/searx.search.processors.html#searx.search.processors.online.default_request_params">[docs]</a> +<span class="k">def</span> <span class="nf">default_request_params</span><span class="p">():</span> +<span class="w"> </span><span class="sd">"""Default request parameters for ``online`` engines."""</span> + <span class="k">return</span> <span class="p">{</span> + <span class="c1"># fmt: off</span> + <span class="s1">'method'</span><span class="p">:</span> <span class="s1">'GET'</span><span class="p">,</span> + <span class="s1">'headers'</span><span class="p">:</span> <span class="p">{},</span> + <span class="s1">'data'</span><span class="p">:</span> <span class="p">{},</span> + <span class="s1">'url'</span><span class="p">:</span> <span class="s1">''</span><span class="p">,</span> + <span class="s1">'cookies'</span><span class="p">:</span> <span class="p">{},</span> + <span class="s1">'auth'</span><span class="p">:</span> <span class="kc">None</span> + <span class="c1"># fmt: on</span> + <span class="p">}</span></div> + + + +<div class="viewcode-block" id="OnlineProcessor"> +<a class="viewcode-back" href="../../../../src/searx.search.processors.html#searx.search.processors.online.OnlineProcessor">[docs]</a> +<span class="k">class</span> <span class="nc">OnlineProcessor</span><span class="p">(</span><span class="n">EngineProcessor</span><span class="p">):</span> +<span class="w"> </span><span class="sd">"""Processor class for ``online`` engines."""</span> + + <span class="n">engine_type</span> <span class="o">=</span> <span class="s1">'online'</span> + + <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="c1"># set timeout for all HTTP requests</span> + <span class="n">searx</span><span class="o">.</span><span class="n">network</span><span class="o">.</span><span class="n">set_timeout_for_thread</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="o">.</span><span class="n">timeout</span><span class="p">,</span> <span class="n">start_time</span><span class="o">=</span><span class="n">default_timer</span><span class="p">())</span> + <span class="c1"># reset the HTTP total time</span> + <span class="n">searx</span><span class="o">.</span><span class="n">network</span><span class="o">.</span><span class="n">reset_time_for_thread</span><span class="p">()</span> + <span class="c1"># set the network</span> + <span class="n">searx</span><span class="o">.</span><span class="n">network</span><span class="o">.</span><span class="n">set_context_network_name</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">)</span> + <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">initialize</span><span class="p">()</span> + +<div class="viewcode-block" id="OnlineProcessor.get_params"> +<a class="viewcode-back" href="../../../../src/searx.search.processors.html#searx.search.processors.online.OnlineProcessor.get_params">[docs]</a> + <span class="k">def</span> <span class="nf">get_params</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search_query</span><span class="p">,</span> <span class="n">engine_category</span><span class="p">):</span> +<span class="w"> </span><span class="sd">"""Returns a set of :ref:`request params <engine request online>` or ``None``</span> +<span class="sd"> if request is not supported.</span> +<span class="sd"> """</span> + <span class="n">params</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_params</span><span class="p">(</span><span class="n">search_query</span><span class="p">,</span> <span class="n">engine_category</span><span class="p">)</span> + <span class="k">if</span> <span class="n">params</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> + <span class="k">return</span> <span class="kc">None</span> + + <span class="c1"># add default params</span> + <span class="n">params</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">default_request_params</span><span class="p">())</span> + + <span class="c1"># add an user agent</span> + <span class="n">params</span><span class="p">[</span><span class="s1">'headers'</span><span class="p">][</span><span class="s1">'User-Agent'</span><span class="p">]</span> <span class="o">=</span> <span class="n">gen_useragent</span><span class="p">()</span> + + <span class="c1"># add Accept-Language header</span> + <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="o">.</span><span class="n">send_accept_language_header</span> <span class="ow">and</span> <span class="n">search_query</span><span class="o">.</span><span class="n">locale</span><span class="p">:</span> + <span class="n">ac_lang</span> <span class="o">=</span> <span class="n">search_query</span><span class="o">.</span><span class="n">locale</span><span class="o">.</span><span class="n">language</span> + <span class="k">if</span> <span class="n">search_query</span><span class="o">.</span><span class="n">locale</span><span class="o">.</span><span class="n">territory</span><span class="p">:</span> + <span class="n">ac_lang</span> <span class="o">=</span> <span class="s2">"</span><span class="si">%s</span><span class="s2">-</span><span class="si">%s</span><span class="s2">,</span><span class="si">%s</span><span class="s2">;q=0.9,*;q=0.5"</span> <span class="o">%</span> <span class="p">(</span> + <span class="n">search_query</span><span class="o">.</span><span class="n">locale</span><span class="o">.</span><span class="n">language</span><span class="p">,</span> + <span class="n">search_query</span><span class="o">.</span><span class="n">locale</span><span class="o">.</span><span class="n">territory</span><span class="p">,</span> + <span class="n">search_query</span><span class="o">.</span><span class="n">locale</span><span class="o">.</span><span class="n">language</span><span class="p">,</span> + <span class="p">)</span> + <span class="n">params</span><span class="p">[</span><span class="s1">'headers'</span><span class="p">][</span><span class="s1">'Accept-Language'</span><span class="p">]</span> <span class="o">=</span> <span class="n">ac_lang</span> + + <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">'HTTP Accept-Language: </span><span class="si">%s</span><span class="s1">'</span><span class="p">,</span> <span class="n">params</span><span class="p">[</span><span class="s1">'headers'</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'Accept-Language'</span><span class="p">,</span> <span class="s1">''</span><span class="p">))</span> + <span class="k">return</span> <span class="n">params</span></div> + + + <span class="k">def</span> <span class="nf">_send_http_request</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">params</span><span class="p">):</span> + <span class="c1"># create dictionary which contain all</span> + <span class="c1"># information about the request</span> + <span class="n">request_args</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">headers</span><span class="o">=</span><span class="n">params</span><span class="p">[</span><span class="s1">'headers'</span><span class="p">],</span> <span class="n">cookies</span><span class="o">=</span><span class="n">params</span><span class="p">[</span><span class="s1">'cookies'</span><span class="p">],</span> <span class="n">auth</span><span class="o">=</span><span class="n">params</span><span class="p">[</span><span class="s1">'auth'</span><span class="p">])</span> + + <span class="c1"># verify</span> + <span class="c1"># if not None, it overrides the verify value defined in the network.</span> + <span class="c1"># use False to accept any server certificate</span> + <span class="c1"># use a path to file to specify a server certificate</span> + <span class="n">verify</span> <span class="o">=</span> <span class="n">params</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'verify'</span><span class="p">)</span> + <span class="k">if</span> <span class="n">verify</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> + <span class="n">request_args</span><span class="p">[</span><span class="s1">'verify'</span><span class="p">]</span> <span class="o">=</span> <span class="n">params</span><span class="p">[</span><span class="s1">'verify'</span><span class="p">]</span> + + <span class="c1"># max_redirects</span> + <span class="n">max_redirects</span> <span class="o">=</span> <span class="n">params</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'max_redirects'</span><span class="p">)</span> + <span class="k">if</span> <span class="n">max_redirects</span><span class="p">:</span> + <span class="n">request_args</span><span class="p">[</span><span class="s1">'max_redirects'</span><span class="p">]</span> <span class="o">=</span> <span class="n">max_redirects</span> + + <span class="c1"># allow_redirects</span> + <span class="k">if</span> <span class="s1">'allow_redirects'</span> <span class="ow">in</span> <span class="n">params</span><span class="p">:</span> + <span class="n">request_args</span><span class="p">[</span><span class="s1">'allow_redirects'</span><span class="p">]</span> <span class="o">=</span> <span class="n">params</span><span class="p">[</span><span class="s1">'allow_redirects'</span><span class="p">]</span> + + <span class="c1"># soft_max_redirects</span> + <span class="n">soft_max_redirects</span> <span class="o">=</span> <span class="n">params</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'soft_max_redirects'</span><span class="p">,</span> <span class="n">max_redirects</span> <span class="ow">or</span> <span class="mi">0</span><span class="p">)</span> + + <span class="c1"># raise_for_status</span> + <span class="n">request_args</span><span class="p">[</span><span class="s1">'raise_for_httperror'</span><span class="p">]</span> <span class="o">=</span> <span class="n">params</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'raise_for_httperror'</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span> + + <span class="c1"># specific type of request (GET or POST)</span> + <span class="k">if</span> <span class="n">params</span><span class="p">[</span><span class="s1">'method'</span><span class="p">]</span> <span class="o">==</span> <span class="s1">'GET'</span><span class="p">:</span> + <span class="n">req</span> <span class="o">=</span> <span class="n">searx</span><span class="o">.</span><span class="n">network</span><span class="o">.</span><span class="n">get</span> + <span class="k">else</span><span class="p">:</span> + <span class="n">req</span> <span class="o">=</span> <span class="n">searx</span><span class="o">.</span><span class="n">network</span><span class="o">.</span><span class="n">post</span> + + <span class="n">request_args</span><span class="p">[</span><span class="s1">'data'</span><span class="p">]</span> <span class="o">=</span> <span class="n">params</span><span class="p">[</span><span class="s1">'data'</span><span class="p">]</span> + + <span class="c1"># send the request</span> + <span class="n">response</span> <span class="o">=</span> <span class="n">req</span><span class="p">(</span><span class="n">params</span><span class="p">[</span><span class="s1">'url'</span><span class="p">],</span> <span class="o">**</span><span class="n">request_args</span><span class="p">)</span> + + <span class="c1"># check soft limit of the redirect count</span> + <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">history</span><span class="p">)</span> <span class="o">></span> <span class="n">soft_max_redirects</span><span class="p">:</span> + <span class="c1"># unexpected redirect : record an error</span> + <span class="c1"># but the engine might still return valid results.</span> + <span class="n">status_code</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="ow">or</span> <span class="s1">''</span><span class="p">)</span> + <span class="n">reason</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">reason_phrase</span> <span class="ow">or</span> <span class="s1">''</span> + <span class="n">hostname</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">url</span><span class="o">.</span><span class="n">host</span> + <span class="n">count_error</span><span class="p">(</span> + <span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">,</span> + <span class="s1">'</span><span class="si">{}</span><span class="s1"> redirects, maximum: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">history</span><span class="p">),</span> <span class="n">soft_max_redirects</span><span class="p">),</span> + <span class="p">(</span><span class="n">status_code</span><span class="p">,</span> <span class="n">reason</span><span class="p">,</span> <span class="n">hostname</span><span class="p">),</span> + <span class="n">secondary</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> + <span class="p">)</span> + + <span class="k">return</span> <span class="n">response</span> + + <span class="k">def</span> <span class="nf">_search_basic</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">query</span><span class="p">,</span> <span class="n">params</span><span class="p">):</span> + <span class="c1"># update request parameters dependent on</span> + <span class="c1"># search-engine (contained in engines folder)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="n">query</span><span class="p">,</span> <span class="n">params</span><span class="p">)</span> + + <span class="c1"># ignoring empty urls</span> + <span class="k">if</span> <span class="ow">not</span> <span class="n">params</span><span class="p">[</span><span class="s1">'url'</span><span class="p">]:</span> + <span class="k">return</span> <span class="kc">None</span> + + <span class="c1"># send request</span> + <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_send_http_request</span><span class="p">(</span><span class="n">params</span><span class="p">)</span> + + <span class="c1"># parse the response</span> + <span class="n">response</span><span class="o">.</span><span class="n">search_params</span> <span class="o">=</span> <span class="n">params</span> + <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="o">.</span><span class="n">response</span><span class="p">(</span><span class="n">response</span><span class="p">)</span> + + <span class="k">def</span> <span class="nf">search</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">query</span><span class="p">,</span> <span class="n">params</span><span class="p">,</span> <span class="n">result_container</span><span class="p">,</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">timeout_limit</span><span class="p">):</span> + <span class="c1"># set timeout for all HTTP requests</span> + <span class="n">searx</span><span class="o">.</span><span class="n">network</span><span class="o">.</span><span class="n">set_timeout_for_thread</span><span class="p">(</span><span class="n">timeout_limit</span><span class="p">,</span> <span class="n">start_time</span><span class="o">=</span><span class="n">start_time</span><span class="p">)</span> + <span class="c1"># reset the HTTP total time</span> + <span class="n">searx</span><span class="o">.</span><span class="n">network</span><span class="o">.</span><span class="n">reset_time_for_thread</span><span class="p">()</span> + <span class="c1"># set the network</span> + <span class="n">searx</span><span class="o">.</span><span class="n">network</span><span class="o">.</span><span class="n">set_context_network_name</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">)</span> + + <span class="k">try</span><span class="p">:</span> + <span class="c1"># send requests and parse the results</span> + <span class="n">search_results</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_search_basic</span><span class="p">(</span><span class="n">query</span><span class="p">,</span> <span class="n">params</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">extend_container</span><span class="p">(</span><span class="n">result_container</span><span class="p">,</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">search_results</span><span class="p">)</span> + <span class="k">except</span> <span class="n">ssl</span><span class="o">.</span><span class="n">SSLError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> + <span class="c1"># requests timeout (connect or read)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">handle_exception</span><span class="p">(</span><span class="n">result_container</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">suspend</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"SSLError </span><span class="si">{}</span><span class="s2">, verify=</span><span class="si">{}</span><span class="s2">"</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">searx</span><span class="o">.</span><span class="n">network</span><span class="o">.</span><span class="n">get_network</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine_name</span><span class="p">)</span><span class="o">.</span><span class="n">verify</span><span class="p">))</span> + <span class="k">except</span> <span class="p">(</span><span class="n">httpx</span><span class="o">.</span><span class="n">TimeoutException</span><span class="p">,</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">TimeoutError</span><span class="p">)</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> + <span class="c1"># requests timeout (connect or read)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">handle_exception</span><span class="p">(</span><span class="n">result_container</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">suspend</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span> + <span class="s2">"HTTP requests timeout (search duration : </span><span class="si">{0}</span><span class="s2"> s, timeout: </span><span class="si">{1}</span><span class="s2"> s) : </span><span class="si">{2}</span><span class="s2">"</span><span class="o">.</span><span class="n">format</span><span class="p">(</span> + <span class="n">default_timer</span><span class="p">()</span> <span class="o">-</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">timeout_limit</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> + <span class="p">)</span> + <span class="p">)</span> + <span class="k">except</span> <span class="p">(</span><span class="n">httpx</span><span class="o">.</span><span class="n">HTTPError</span><span class="p">,</span> <span class="n">httpx</span><span class="o">.</span><span class="n">StreamError</span><span class="p">)</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> + <span class="c1"># other requests exception</span> + <span class="bp">self</span><span class="o">.</span><span class="n">handle_exception</span><span class="p">(</span><span class="n">result_container</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">suspend</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span> + <span class="s2">"requests exception (search duration : </span><span class="si">{0}</span><span class="s2"> s, timeout: </span><span class="si">{1}</span><span class="s2"> s) : </span><span class="si">{2}</span><span class="s2">"</span><span class="o">.</span><span class="n">format</span><span class="p">(</span> + <span class="n">default_timer</span><span class="p">()</span> <span class="o">-</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">timeout_limit</span><span class="p">,</span> <span class="n">e</span> + <span class="p">)</span> + <span class="p">)</span> + <span class="k">except</span> <span class="n">SearxEngineCaptchaException</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> + <span class="bp">self</span><span class="o">.</span><span class="n">handle_exception</span><span class="p">(</span><span class="n">result_container</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">suspend</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="s1">'CAPTCHA'</span><span class="p">)</span> + <span class="k">except</span> <span class="n">SearxEngineTooManyRequestsException</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> + <span class="bp">self</span><span class="o">.</span><span class="n">handle_exception</span><span class="p">(</span><span class="n">result_container</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">suspend</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="s1">'Too many requests'</span><span class="p">)</span> + <span class="k">except</span> <span class="n">SearxEngineAccessDeniedException</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> + <span class="bp">self</span><span class="o">.</span><span class="n">handle_exception</span><span class="p">(</span><span class="n">result_container</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">suspend</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="s1">'SearXNG is blocked'</span><span class="p">)</span> + <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> <span class="c1"># pylint: disable=broad-except</span> + <span class="bp">self</span><span class="o">.</span><span class="n">handle_exception</span><span class="p">(</span><span class="n">result_container</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="s1">'exception : </span><span class="si">{0}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">e</span><span class="p">))</span> + + <span class="k">def</span> <span class="nf">get_default_tests</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="n">tests</span> <span class="o">=</span> <span class="p">{}</span> + + <span class="n">tests</span><span class="p">[</span><span class="s1">'simple'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span> + <span class="s1">'matrix'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'query'</span><span class="p">:</span> <span class="p">(</span><span class="s1">'life'</span><span class="p">,</span> <span class="s1">'computer'</span><span class="p">)},</span> + <span class="s1">'result_container'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'not_empty'</span><span class="p">],</span> + <span class="p">}</span> + + <span class="k">if</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="p">,</span> <span class="s1">'paging'</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span> + <span class="n">tests</span><span class="p">[</span><span class="s1">'paging'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span> + <span class="s1">'matrix'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'query'</span><span class="p">:</span> <span class="s1">'time'</span><span class="p">,</span> <span class="s1">'pageno'</span><span class="p">:</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)},</span> + <span class="s1">'result_container'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'not_empty'</span><span class="p">],</span> + <span class="s1">'test'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'unique_results'</span><span class="p">],</span> + <span class="p">}</span> + <span class="k">if</span> <span class="s1">'general'</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="o">.</span><span class="n">categories</span><span class="p">:</span> + <span class="c1"># avoid documentation about HTML tags (<time> and <input type="time">)</span> + <span class="n">tests</span><span class="p">[</span><span class="s1">'paging'</span><span class="p">][</span><span class="s1">'matrix'</span><span class="p">][</span><span class="s1">'query'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'news'</span> + + <span class="k">if</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="p">,</span> <span class="s1">'time_range'</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span> + <span class="n">tests</span><span class="p">[</span><span class="s1">'time_range'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span> + <span class="s1">'matrix'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'query'</span><span class="p">:</span> <span class="s1">'news'</span><span class="p">,</span> <span class="s1">'time_range'</span><span class="p">:</span> <span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="s1">'day'</span><span class="p">)},</span> + <span class="s1">'result_container'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'not_empty'</span><span class="p">],</span> + <span class="s1">'test'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'unique_results'</span><span class="p">],</span> + <span class="p">}</span> + + <span class="k">if</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="p">,</span> <span class="s1">'traits'</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span> + <span class="n">tests</span><span class="p">[</span><span class="s1">'lang_fr'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span> + <span class="s1">'matrix'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'query'</span><span class="p">:</span> <span class="s1">'paris'</span><span class="p">,</span> <span class="s1">'lang'</span><span class="p">:</span> <span class="s1">'fr'</span><span class="p">},</span> + <span class="s1">'result_container'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'not_empty'</span><span class="p">,</span> <span class="p">(</span><span class="s1">'has_language'</span><span class="p">,</span> <span class="s1">'fr'</span><span class="p">)],</span> + <span class="p">}</span> + <span class="n">tests</span><span class="p">[</span><span class="s1">'lang_en'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span> + <span class="s1">'matrix'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'query'</span><span class="p">:</span> <span class="s1">'paris'</span><span class="p">,</span> <span class="s1">'lang'</span><span class="p">:</span> <span class="s1">'en'</span><span class="p">},</span> + <span class="s1">'result_container'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'not_empty'</span><span class="p">,</span> <span class="p">(</span><span class="s1">'has_language'</span><span class="p">,</span> <span class="s1">'en'</span><span class="p">)],</span> + <span class="p">}</span> + + <span class="k">if</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="p">,</span> <span class="s1">'safesearch'</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span> + <span class="n">tests</span><span class="p">[</span><span class="s1">'safesearch'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'matrix'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'query'</span><span class="p">:</span> <span class="s1">'porn'</span><span class="p">,</span> <span class="s1">'safesearch'</span><span class="p">:</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">)},</span> <span class="s1">'test'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'unique_results'</span><span class="p">]}</span> + + <span class="k">return</span> <span class="n">tests</span></div> + +</pre></div> + + <div class="clearer"></div> + </div> + </div> + </div> + <span id="sidebar-top"></span> + <div class="sphinxsidebar" role="navigation" aria-label="Main"> + <div class="sphinxsidebarwrapper"> + + + <p class="logo"><a href="../../../../index.html"> + <img class="logo" src="../../../../_static/searxng-wordmark.svg" alt="Logo of SearXNG"/> + </a></p> + + +<h3><a href="../../../../index.html">Table of Contents</a></h3> +<ul> +<li class="toctree-l1"><a class="reference internal" href="../../../../user/index.html">User information</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../own-instance.html">Why use a private instance?</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../admin/index.html">Administrator documentation</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../dev/index.html">Developer documentation</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../utils/index.html">DevOps tooling box</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../src/index.html">Source-Code</a></li> +</ul> + + <h3>Project Links</h3> + <ul> + <li><a href="https://github.com/searxng/searxng/tree/master">Source</a> + + <li><a href="https://github.com/searxng/searxng/wiki">Wiki</a> + + <li><a href="https://searx.space">Public instances</a> + + <li><a href="https://github.com/searxng/searxng/issues">Issue Tracker</a> + </ul><h3>Navigation</h3> +<ul> + <li><a href="../../../../index.html">Overview</a> + <ul> + <li><a href="../../../index.html">Module code</a> + <ul> + <li><a href="../../search.html">searx.search</a> + + + </ul> + </li></ul> + </li> + </ul> + </li> +</ul> +<search id="searchbox" style="display: none" role="search"> + <h3 id="searchlabel">Quick search</h3> + <div class="searchformwrapper"> + <form class="search" action="../../../../search.html" method="get"> + <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> + <input type="submit" value="Go" /> + </form> + </div> +</search> +<script>document.getElementById('searchbox').style.display = "block"</script> + </div> + </div> + <div class="clearer"></div> + </div> + <div class="footer" role="contentinfo"> + © Copyright SearXNG team. + </div> + </body> +</html>
\ No newline at end of file diff --git a/_modules/searx/search/processors/online_currency.html b/_modules/searx/search/processors/online_currency.html new file mode 100644 index 000000000..9cc8a1442 --- /dev/null +++ b/_modules/searx/search/processors/online_currency.html @@ -0,0 +1,187 @@ +<!DOCTYPE html> + +<html lang="en" data-content_root="../../../../"> + <head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>searx.search.processors.online_currency — SearXNG Documentation (2025.1.6+6dab7fe78)</title> + <link rel="stylesheet" type="text/css" href="../../../../_static/pygments.css?v=4f649999" /> + <link rel="stylesheet" type="text/css" href="../../../../_static/searxng.css?v=52e4ff28" /> + <script src="../../../../_static/documentation_options.js?v=ef740023"></script> + <script src="../../../../_static/doctools.js?v=9a2dae69"></script> + <script src="../../../../_static/sphinx_highlight.js?v=dc90522c"></script> + <script data-project="searxng" data-version="2025.1.6+6dab7fe78" src="../../../../_static/describe_version.js?v=fa7f30d0"></script> + <link rel="index" title="Index" href="../../../../genindex.html" /> + <link rel="search" title="Search" href="../../../../search.html" /> + </head><body> + <div class="related" role="navigation" aria-label="Related"> + <h3>Navigation</h3> + <ul> + <li class="right" style="margin-right: 10px"> + <a href="../../../../genindex.html" title="General Index" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../../../py-modindex.html" title="Python Module Index" + >modules</a> |</li> + <li class="nav-item nav-item-0"><a href="../../../../index.html">SearXNG Documentation (2025.1.6+6dab7fe78)</a> »</li> + <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> »</li> + <li class="nav-item nav-item-2"><a href="../../search.html" accesskey="U">searx.search</a> »</li> + <li class="nav-item nav-item-this"><a href="">searx.search.processors.online_currency</a></li> + </ul> + </div> + + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body" role="main"> + + <h1>Source code for searx.search.processors.online_currency</h1><div class="highlight"><pre> +<span></span><span class="c1"># SPDX-License-Identifier: AGPL-3.0-or-later</span> +<span class="sd">"""Processors for engine-type: ``online_currency``</span> + +<span class="sd">"""</span> + +<span class="kn">import</span> <span class="nn">unicodedata</span> +<span class="kn">import</span> <span class="nn">re</span> + +<span class="kn">from</span> <span class="nn">searx.data</span> <span class="kn">import</span> <span class="n">CURRENCIES</span> +<span class="kn">from</span> <span class="nn">.online</span> <span class="kn">import</span> <span class="n">OnlineProcessor</span> + +<span class="n">parser_re</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s1">'.*?(</span><span class="se">\\</span><span class="s1">d+(?:</span><span class="se">\\</span><span class="s1">.</span><span class="se">\\</span><span class="s1">d+)?) ([^.0-9]+) (?:in|to) ([^.0-9]+)'</span><span class="p">,</span> <span class="n">re</span><span class="o">.</span><span class="n">I</span><span class="p">)</span> + + +<span class="k">def</span> <span class="nf">normalize_name</span><span class="p">(</span><span class="n">name</span><span class="p">):</span> + <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'-'</span><span class="p">,</span> <span class="s1">' '</span><span class="p">)</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="s1">'s'</span><span class="p">)</span> + <span class="n">name</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s1">' +'</span><span class="p">,</span> <span class="s1">' '</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span> + <span class="k">return</span> <span class="n">unicodedata</span><span class="o">.</span><span class="n">normalize</span><span class="p">(</span><span class="s1">'NFKD'</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> + + +<span class="k">def</span> <span class="nf">name_to_iso4217</span><span class="p">(</span><span class="n">name</span><span class="p">):</span> + <span class="n">name</span> <span class="o">=</span> <span class="n">normalize_name</span><span class="p">(</span><span class="n">name</span><span class="p">)</span> + <span class="n">currency</span> <span class="o">=</span> <span class="n">CURRENCIES</span><span class="p">[</span><span class="s1">'names'</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="p">[</span><span class="n">name</span><span class="p">])</span> + <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">currency</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> + <span class="k">return</span> <span class="n">currency</span> + <span class="k">return</span> <span class="n">currency</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> + + +<span class="k">def</span> <span class="nf">iso4217_to_name</span><span class="p">(</span><span class="n">iso4217</span><span class="p">,</span> <span class="n">language</span><span class="p">):</span> + <span class="k">return</span> <span class="n">CURRENCIES</span><span class="p">[</span><span class="s1">'iso4217'</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">iso4217</span><span class="p">,</span> <span class="p">{})</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">language</span><span class="p">,</span> <span class="n">iso4217</span><span class="p">)</span> + + +<div class="viewcode-block" id="OnlineCurrencyProcessor"> +<a class="viewcode-back" href="../../../../src/searx.search.processors.html#searx.search.processors.online_currency.OnlineCurrencyProcessor">[docs]</a> +<span class="k">class</span> <span class="nc">OnlineCurrencyProcessor</span><span class="p">(</span><span class="n">OnlineProcessor</span><span class="p">):</span> +<span class="w"> </span><span class="sd">"""Processor class used by ``online_currency`` engines."""</span> + + <span class="n">engine_type</span> <span class="o">=</span> <span class="s1">'online_currency'</span> + +<div class="viewcode-block" id="OnlineCurrencyProcessor.get_params"> +<a class="viewcode-back" href="../../../../src/searx.search.processors.html#searx.search.processors.online_currency.OnlineCurrencyProcessor.get_params">[docs]</a> + <span class="k">def</span> <span class="nf">get_params</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search_query</span><span class="p">,</span> <span class="n">engine_category</span><span class="p">):</span> +<span class="w"> </span><span class="sd">"""Returns a set of :ref:`request params <engine request online_currency>`</span> +<span class="sd"> or ``None`` if search query does not match to :py:obj:`parser_re`."""</span> + + <span class="n">params</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_params</span><span class="p">(</span><span class="n">search_query</span><span class="p">,</span> <span class="n">engine_category</span><span class="p">)</span> + <span class="k">if</span> <span class="n">params</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> + <span class="k">return</span> <span class="kc">None</span> + + <span class="n">m</span> <span class="o">=</span> <span class="n">parser_re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">search_query</span><span class="o">.</span><span class="n">query</span><span class="p">)</span> + <span class="k">if</span> <span class="ow">not</span> <span class="n">m</span><span class="p">:</span> + <span class="k">return</span> <span class="kc">None</span> + + <span class="n">amount_str</span><span class="p">,</span> <span class="n">from_currency</span><span class="p">,</span> <span class="n">to_currency</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">groups</span><span class="p">()</span> + <span class="k">try</span><span class="p">:</span> + <span class="n">amount</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">amount_str</span><span class="p">)</span> + <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> + <span class="k">return</span> <span class="kc">None</span> + <span class="n">from_currency</span> <span class="o">=</span> <span class="n">name_to_iso4217</span><span class="p">(</span><span class="n">from_currency</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span> + <span class="n">to_currency</span> <span class="o">=</span> <span class="n">name_to_iso4217</span><span class="p">(</span><span class="n">to_currency</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span> + + <span class="n">params</span><span class="p">[</span><span class="s1">'amount'</span><span class="p">]</span> <span class="o">=</span> <span class="n">amount</span> + <span class="n">params</span><span class="p">[</span><span class="s1">'from'</span><span class="p">]</span> <span class="o">=</span> <span class="n">from_currency</span> + <span class="n">params</span><span class="p">[</span><span class="s1">'to'</span><span class="p">]</span> <span class="o">=</span> <span class="n">to_currency</span> + <span class="n">params</span><span class="p">[</span><span class="s1">'from_name'</span><span class="p">]</span> <span class="o">=</span> <span class="n">iso4217_to_name</span><span class="p">(</span><span class="n">from_currency</span><span class="p">,</span> <span class="s1">'en'</span><span class="p">)</span> + <span class="n">params</span><span class="p">[</span><span class="s1">'to_name'</span><span class="p">]</span> <span class="o">=</span> <span class="n">iso4217_to_name</span><span class="p">(</span><span class="n">to_currency</span><span class="p">,</span> <span class="s1">'en'</span><span class="p">)</span> + <span class="k">return</span> <span class="n">params</span></div> + + + <span class="k">def</span> <span class="nf">get_default_tests</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="n">tests</span> <span class="o">=</span> <span class="p">{}</span> + + <span class="n">tests</span><span class="p">[</span><span class="s1">'currency'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span> + <span class="s1">'matrix'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'query'</span><span class="p">:</span> <span class="s1">'1337 usd in rmb'</span><span class="p">},</span> + <span class="s1">'result_container'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'has_answer'</span><span class="p">],</span> + <span class="p">}</span> + + <span class="k">return</span> <span class="n">tests</span></div> + +</pre></div> + + <div class="clearer"></div> + </div> + </div> + </div> + <span id="sidebar-top"></span> + <div class="sphinxsidebar" role="navigation" aria-label="Main"> + <div class="sphinxsidebarwrapper"> + + + <p class="logo"><a href="../../../../index.html"> + <img class="logo" src="../../../../_static/searxng-wordmark.svg" alt="Logo of SearXNG"/> + </a></p> + + +<h3><a href="../../../../index.html">Table of Contents</a></h3> +<ul> +<li class="toctree-l1"><a class="reference internal" href="../../../../user/index.html">User information</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../own-instance.html">Why use a private instance?</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../admin/index.html">Administrator documentation</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../dev/index.html">Developer documentation</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../utils/index.html">DevOps tooling box</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../src/index.html">Source-Code</a></li> +</ul> + + <h3>Project Links</h3> + <ul> + <li><a href="https://github.com/searxng/searxng/tree/master">Source</a> + + <li><a href="https://github.com/searxng/searxng/wiki">Wiki</a> + + <li><a href="https://searx.space">Public instances</a> + + <li><a href="https://github.com/searxng/searxng/issues">Issue Tracker</a> + </ul><h3>Navigation</h3> +<ul> + <li><a href="../../../../index.html">Overview</a> + <ul> + <li><a href="../../../index.html">Module code</a> + <ul> + <li><a href="../../search.html">searx.search</a> + + + </ul> + </li></ul> + </li> + </ul> + </li> +</ul> +<search id="searchbox" style="display: none" role="search"> + <h3 id="searchlabel">Quick search</h3> + <div class="searchformwrapper"> + <form class="search" action="../../../../search.html" method="get"> + <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> + <input type="submit" value="Go" /> + </form> + </div> +</search> +<script>document.getElementById('searchbox').style.display = "block"</script> + </div> + </div> + <div class="clearer"></div> + </div> + <div class="footer" role="contentinfo"> + © Copyright SearXNG team. + </div> + </body> +</html>
\ No newline at end of file diff --git a/_modules/searx/search/processors/online_dictionary.html b/_modules/searx/search/processors/online_dictionary.html new file mode 100644 index 000000000..a479b8f25 --- /dev/null +++ b/_modules/searx/search/processors/online_dictionary.html @@ -0,0 +1,174 @@ +<!DOCTYPE html> + +<html lang="en" data-content_root="../../../../"> + <head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>searx.search.processors.online_dictionary — SearXNG Documentation (2025.1.6+6dab7fe78)</title> + <link rel="stylesheet" type="text/css" href="../../../../_static/pygments.css?v=4f649999" /> + <link rel="stylesheet" type="text/css" href="../../../../_static/searxng.css?v=52e4ff28" /> + <script src="../../../../_static/documentation_options.js?v=ef740023"></script> + <script src="../../../../_static/doctools.js?v=9a2dae69"></script> + <script src="../../../../_static/sphinx_highlight.js?v=dc90522c"></script> + <script data-project="searxng" data-version="2025.1.6+6dab7fe78" src="../../../../_static/describe_version.js?v=fa7f30d0"></script> + <link rel="index" title="Index" href="../../../../genindex.html" /> + <link rel="search" title="Search" href="../../../../search.html" /> + </head><body> + <div class="related" role="navigation" aria-label="Related"> + <h3>Navigation</h3> + <ul> + <li class="right" style="margin-right: 10px"> + <a href="../../../../genindex.html" title="General Index" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../../../py-modindex.html" title="Python Module Index" + >modules</a> |</li> + <li class="nav-item nav-item-0"><a href="../../../../index.html">SearXNG Documentation (2025.1.6+6dab7fe78)</a> »</li> + <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> »</li> + <li class="nav-item nav-item-2"><a href="../../search.html" accesskey="U">searx.search</a> »</li> + <li class="nav-item nav-item-this"><a href="">searx.search.processors.online_dictionary</a></li> + </ul> + </div> + + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body" role="main"> + + <h1>Source code for searx.search.processors.online_dictionary</h1><div class="highlight"><pre> +<span></span><span class="c1"># SPDX-License-Identifier: AGPL-3.0-or-later</span> +<span class="sd">"""Processors for engine-type: ``online_dictionary``</span> + +<span class="sd">"""</span> + +<span class="kn">import</span> <span class="nn">re</span> + +<span class="kn">from</span> <span class="nn">searx.utils</span> <span class="kn">import</span> <span class="n">is_valid_lang</span> +<span class="kn">from</span> <span class="nn">.online</span> <span class="kn">import</span> <span class="n">OnlineProcessor</span> + +<span class="n">parser_re</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s1">'.*?([a-z]+)-([a-z]+) (.+)$'</span><span class="p">,</span> <span class="n">re</span><span class="o">.</span><span class="n">I</span><span class="p">)</span> + + +<div class="viewcode-block" id="OnlineDictionaryProcessor"> +<a class="viewcode-back" href="../../../../src/searx.search.processors.html#searx.search.processors.online_dictionary.OnlineDictionaryProcessor">[docs]</a> +<span class="k">class</span> <span class="nc">OnlineDictionaryProcessor</span><span class="p">(</span><span class="n">OnlineProcessor</span><span class="p">):</span> +<span class="w"> </span><span class="sd">"""Processor class used by ``online_dictionary`` engines."""</span> + + <span class="n">engine_type</span> <span class="o">=</span> <span class="s1">'online_dictionary'</span> + +<div class="viewcode-block" id="OnlineDictionaryProcessor.get_params"> +<a class="viewcode-back" href="../../../../src/searx.search.processors.html#searx.search.processors.online_dictionary.OnlineDictionaryProcessor.get_params">[docs]</a> + <span class="k">def</span> <span class="nf">get_params</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search_query</span><span class="p">,</span> <span class="n">engine_category</span><span class="p">):</span> +<span class="w"> </span><span class="sd">"""Returns a set of :ref:`request params <engine request online_dictionary>` or</span> +<span class="sd"> ``None`` if search query does not match to :py:obj:`parser_re`.</span> +<span class="sd"> """</span> + <span class="n">params</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_params</span><span class="p">(</span><span class="n">search_query</span><span class="p">,</span> <span class="n">engine_category</span><span class="p">)</span> + <span class="k">if</span> <span class="n">params</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> + <span class="k">return</span> <span class="kc">None</span> + + <span class="n">m</span> <span class="o">=</span> <span class="n">parser_re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">search_query</span><span class="o">.</span><span class="n">query</span><span class="p">)</span> + <span class="k">if</span> <span class="ow">not</span> <span class="n">m</span><span class="p">:</span> + <span class="k">return</span> <span class="kc">None</span> + + <span class="n">from_lang</span><span class="p">,</span> <span class="n">to_lang</span><span class="p">,</span> <span class="n">query</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">groups</span><span class="p">()</span> + + <span class="n">from_lang</span> <span class="o">=</span> <span class="n">is_valid_lang</span><span class="p">(</span><span class="n">from_lang</span><span class="p">)</span> + <span class="n">to_lang</span> <span class="o">=</span> <span class="n">is_valid_lang</span><span class="p">(</span><span class="n">to_lang</span><span class="p">)</span> + + <span class="k">if</span> <span class="ow">not</span> <span class="n">from_lang</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">to_lang</span><span class="p">:</span> + <span class="k">return</span> <span class="kc">None</span> + + <span class="n">params</span><span class="p">[</span><span class="s1">'from_lang'</span><span class="p">]</span> <span class="o">=</span> <span class="n">from_lang</span> + <span class="n">params</span><span class="p">[</span><span class="s1">'to_lang'</span><span class="p">]</span> <span class="o">=</span> <span class="n">to_lang</span> + <span class="n">params</span><span class="p">[</span><span class="s1">'query'</span><span class="p">]</span> <span class="o">=</span> <span class="n">query</span> + + <span class="k">return</span> <span class="n">params</span></div> + + + <span class="k">def</span> <span class="nf">get_default_tests</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="n">tests</span> <span class="o">=</span> <span class="p">{}</span> + + <span class="k">if</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">engine</span><span class="p">,</span> <span class="s1">'paging'</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span> + <span class="n">tests</span><span class="p">[</span><span class="s1">'translation_paging'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span> + <span class="s1">'matrix'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'query'</span><span class="p">:</span> <span class="s1">'en-es house'</span><span class="p">,</span> <span class="s1">'pageno'</span><span class="p">:</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)},</span> + <span class="s1">'result_container'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'not_empty'</span><span class="p">,</span> <span class="p">(</span><span class="s1">'one_title_contains'</span><span class="p">,</span> <span class="s1">'house'</span><span class="p">)],</span> + <span class="s1">'test'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'unique_results'</span><span class="p">],</span> + <span class="p">}</span> + <span class="k">else</span><span class="p">:</span> + <span class="n">tests</span><span class="p">[</span><span class="s1">'translation'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span> + <span class="s1">'matrix'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'query'</span><span class="p">:</span> <span class="s1">'en-es house'</span><span class="p">},</span> + <span class="s1">'result_container'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'not_empty'</span><span class="p">,</span> <span class="p">(</span><span class="s1">'one_title_contains'</span><span class="p">,</span> <span class="s1">'house'</span><span class="p">)],</span> + <span class="p">}</span> + + <span class="k">return</span> <span class="n">tests</span></div> + +</pre></div> + + <div class="clearer"></div> + </div> + </div> + </div> + <span id="sidebar-top"></span> + <div class="sphinxsidebar" role="navigation" aria-label="Main"> + <div class="sphinxsidebarwrapper"> + + + <p class="logo"><a href="../../../../index.html"> + <img class="logo" src="../../../../_static/searxng-wordmark.svg" alt="Logo of SearXNG"/> + </a></p> + + +<h3><a href="../../../../index.html">Table of Contents</a></h3> +<ul> +<li class="toctree-l1"><a class="reference internal" href="../../../../user/index.html">User information</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../own-instance.html">Why use a private instance?</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../admin/index.html">Administrator documentation</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../dev/index.html">Developer documentation</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../utils/index.html">DevOps tooling box</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../src/index.html">Source-Code</a></li> +</ul> + + <h3>Project Links</h3> + <ul> + <li><a href="https://github.com/searxng/searxng/tree/master">Source</a> + + <li><a href="https://github.com/searxng/searxng/wiki">Wiki</a> + + <li><a href="https://searx.space">Public instances</a> + + <li><a href="https://github.com/searxng/searxng/issues">Issue Tracker</a> + </ul><h3>Navigation</h3> +<ul> + <li><a href="../../../../index.html">Overview</a> + <ul> + <li><a href="../../../index.html">Module code</a> + <ul> + <li><a href="../../search.html">searx.search</a> + + + </ul> + </li></ul> + </li> + </ul> + </li> +</ul> +<search id="searchbox" style="display: none" role="search"> + <h3 id="searchlabel">Quick search</h3> + <div class="searchformwrapper"> + <form class="search" action="../../../../search.html" method="get"> + <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> + <input type="submit" value="Go" /> + </form> + </div> +</search> +<script>document.getElementById('searchbox').style.display = "block"</script> + </div> + </div> + <div class="clearer"></div> + </div> + <div class="footer" role="contentinfo"> + © Copyright SearXNG team. + </div> + </body> +</html>
\ No newline at end of file diff --git a/_modules/searx/search/processors/online_url_search.html b/_modules/searx/search/processors/online_url_search.html new file mode 100644 index 000000000..c0c87d4b5 --- /dev/null +++ b/_modules/searx/search/processors/online_url_search.html @@ -0,0 +1,159 @@ +<!DOCTYPE html> + +<html lang="en" data-content_root="../../../../"> + <head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>searx.search.processors.online_url_search — SearXNG Documentation (2025.1.6+6dab7fe78)</title> + <link rel="stylesheet" type="text/css" href="../../../../_static/pygments.css?v=4f649999" /> + <link rel="stylesheet" type="text/css" href="../../../../_static/searxng.css?v=52e4ff28" /> + <script src="../../../../_static/documentation_options.js?v=ef740023"></script> + <script src="../../../../_static/doctools.js?v=9a2dae69"></script> + <script src="../../../../_static/sphinx_highlight.js?v=dc90522c"></script> + <script data-project="searxng" data-version="2025.1.6+6dab7fe78" src="../../../../_static/describe_version.js?v=fa7f30d0"></script> + <link rel="index" title="Index" href="../../../../genindex.html" /> + <link rel="search" title="Search" href="../../../../search.html" /> + </head><body> + <div class="related" role="navigation" aria-label="Related"> + <h3>Navigation</h3> + <ul> + <li class="right" style="margin-right: 10px"> + <a href="../../../../genindex.html" title="General Index" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../../../py-modindex.html" title="Python Module Index" + >modules</a> |</li> + <li class="nav-item nav-item-0"><a href="../../../../index.html">SearXNG Documentation (2025.1.6+6dab7fe78)</a> »</li> + <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> »</li> + <li class="nav-item nav-item-2"><a href="../../search.html" accesskey="U">searx.search</a> »</li> + <li class="nav-item nav-item-this"><a href="">searx.search.processors.online_url_search</a></li> + </ul> + </div> + + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body" role="main"> + + <h1>Source code for searx.search.processors.online_url_search</h1><div class="highlight"><pre> +<span></span><span class="c1"># SPDX-License-Identifier: AGPL-3.0-or-later</span> +<span class="sd">"""Processors for engine-type: ``online_url_search``</span> + +<span class="sd">"""</span> + +<span class="kn">import</span> <span class="nn">re</span> +<span class="kn">from</span> <span class="nn">.online</span> <span class="kn">import</span> <span class="n">OnlineProcessor</span> + +<span class="n">re_search_urls</span> <span class="o">=</span> <span class="p">{</span> + <span class="s1">'http'</span><span class="p">:</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s1">'https?:\/\/[^ ]*'</span><span class="p">),</span> + <span class="s1">'ftp'</span><span class="p">:</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s1">'ftps?:\/\/[^ ]*'</span><span class="p">),</span> + <span class="s1">'data:image'</span><span class="p">:</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s1">'data:image/[^; ]*;base64,[^ ]*'</span><span class="p">),</span> +<span class="p">}</span> + + +<div class="viewcode-block" id="OnlineUrlSearchProcessor"> +<a class="viewcode-back" href="../../../../src/searx.search.processors.html#searx.search.processors.online_url_search.OnlineUrlSearchProcessor">[docs]</a> +<span class="k">class</span> <span class="nc">OnlineUrlSearchProcessor</span><span class="p">(</span><span class="n">OnlineProcessor</span><span class="p">):</span> +<span class="w"> </span><span class="sd">"""Processor class used by ``online_url_search`` engines."""</span> + + <span class="n">engine_type</span> <span class="o">=</span> <span class="s1">'online_url_search'</span> + +<div class="viewcode-block" id="OnlineUrlSearchProcessor.get_params"> +<a class="viewcode-back" href="../../../../src/searx.search.processors.html#searx.search.processors.online_url_search.OnlineUrlSearchProcessor.get_params">[docs]</a> + <span class="k">def</span> <span class="nf">get_params</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search_query</span><span class="p">,</span> <span class="n">engine_category</span><span class="p">):</span> +<span class="w"> </span><span class="sd">"""Returns a set of :ref:`request params <engine request online>` or ``None`` if</span> +<span class="sd"> search query does not match to :py:obj:`re_search_urls`.</span> +<span class="sd"> """</span> + + <span class="n">params</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_params</span><span class="p">(</span><span class="n">search_query</span><span class="p">,</span> <span class="n">engine_category</span><span class="p">)</span> + <span class="k">if</span> <span class="n">params</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> + <span class="k">return</span> <span class="kc">None</span> + + <span class="n">url_match</span> <span class="o">=</span> <span class="kc">False</span> + <span class="n">search_urls</span> <span class="o">=</span> <span class="p">{}</span> + + <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">re_search_urls</span><span class="o">.</span><span class="n">items</span><span class="p">():</span> + <span class="n">m</span> <span class="o">=</span> <span class="n">v</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">search_query</span><span class="o">.</span><span class="n">query</span><span class="p">)</span> + <span class="n">v</span> <span class="o">=</span> <span class="kc">None</span> + <span class="k">if</span> <span class="n">m</span><span class="p">:</span> + <span class="n">url_match</span> <span class="o">=</span> <span class="kc">True</span> + <span class="n">v</span> <span class="o">=</span> <span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> + <span class="n">search_urls</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span> + + <span class="k">if</span> <span class="ow">not</span> <span class="n">url_match</span><span class="p">:</span> + <span class="k">return</span> <span class="kc">None</span> + + <span class="n">params</span><span class="p">[</span><span class="s1">'search_urls'</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_urls</span> + <span class="k">return</span> <span class="n">params</span></div> +</div> + +</pre></div> + + <div class="clearer"></div> + </div> + </div> + </div> + <span id="sidebar-top"></span> + <div class="sphinxsidebar" role="navigation" aria-label="Main"> + <div class="sphinxsidebarwrapper"> + + + <p class="logo"><a href="../../../../index.html"> + <img class="logo" src="../../../../_static/searxng-wordmark.svg" alt="Logo of SearXNG"/> + </a></p> + + +<h3><a href="../../../../index.html">Table of Contents</a></h3> +<ul> +<li class="toctree-l1"><a class="reference internal" href="../../../../user/index.html">User information</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../own-instance.html">Why use a private instance?</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../admin/index.html">Administrator documentation</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../dev/index.html">Developer documentation</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../utils/index.html">DevOps tooling box</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../../../src/index.html">Source-Code</a></li> +</ul> + + <h3>Project Links</h3> + <ul> + <li><a href="https://github.com/searxng/searxng/tree/master">Source</a> + + <li><a href="https://github.com/searxng/searxng/wiki">Wiki</a> + + <li><a href="https://searx.space">Public instances</a> + + <li><a href="https://github.com/searxng/searxng/issues">Issue Tracker</a> + </ul><h3>Navigation</h3> +<ul> + <li><a href="../../../../index.html">Overview</a> + <ul> + <li><a href="../../../index.html">Module code</a> + <ul> + <li><a href="../../search.html">searx.search</a> + + + </ul> + </li></ul> + </li> + </ul> + </li> +</ul> +<search id="searchbox" style="display: none" role="search"> + <h3 id="searchlabel">Quick search</h3> + <div class="searchformwrapper"> + <form class="search" action="../../../../search.html" method="get"> + <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> + <input type="submit" value="Go" /> + </form> + </div> +</search> +<script>document.getElementById('searchbox').style.display = "block"</script> + </div> + </div> + <div class="clearer"></div> + </div> + <div class="footer" role="contentinfo"> + © Copyright SearXNG team. + </div> + </body> +</html>
\ No newline at end of file |