searx/blog/command-line-engines.html

163 lines
11 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<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>Running shell commands to fetch results &#8212; Searx Documentation (Searx-1.1.0.tex)</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../_static/searx.css" />
<link rel="stylesheet" type="text/css" href="../_static/tabs.css" />
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/sphinx_highlight.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="Developing in Linux containers [202006]" href="lxcdev-202006.html" />
<link rel="prev" title="Query your local search engines" href="search-indexer-engines.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<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="right" >
<a href="lxcdev-202006.html" title="Developing in Linux containers [202006]"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="search-indexer-engines.html" title="Query your local search engines"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Searx Documentation (Searx-1.1.0.tex)</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Blog</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Running shell commands to fetch results</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="running-shell-commands-to-fetch-results">
<h1>Running shell commands to fetch results<a class="headerlink" href="#running-shell-commands-to-fetch-results" title="Permalink to this heading"></a></h1>
<p>Previously, with searx you could search over the Internet on other peoples
computers. Now it is possible to fetch results from your local machine without
connecting to any networks from the same graphical user interface.</p>
<section id="command-line-engines">
<h2>Command line engines<a class="headerlink" href="#command-line-engines" title="Permalink to this heading"></a></h2>
<p>In <a class="reference external" href="https://github.com/searx/searx/pull/2128">PR 2128</a> a new type of engine has been introduced called <code class="docutils literal notranslate"><span class="pre">command</span></code>.
This engine lets administrators add engines which run arbitrary shell commands
and show its output on the web UI of searx.</p>
<p>When creating and enabling a <code class="docutils literal notranslate"><span class="pre">command</span></code> engine on a public searx instance,
you must be careful to avoid leaking private data. The easiest solution
is to add tokens to the engine. Thus, only those who have the appropriate token
can retrieve results from the it.</p>
<p>The engine base is flexible. Only your imagination can limit the power of this engine. (And
maybe security concerns.) The following options are available:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">command</span></code>: A comma separated list of the elements of the command. A special token {{QUERY}} tells searx where to put the search terms of the user. Example: <code class="docutils literal notranslate"><span class="pre">['ls',</span> <span class="pre">'-l',</span> <span class="pre">'-h',</span> <span class="pre">'{{QUERY}}']</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">delimiter</span></code>: A dict containing a delimiter char and the “titles” of each element in keys.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">parse_regex</span></code>: A dict containing the regular expressions for each result key.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">query_type</span></code>: The expected type of user search terms. Possible values: <code class="docutils literal notranslate"><span class="pre">path</span></code> and <code class="docutils literal notranslate"><span class="pre">enum</span></code>. <code class="docutils literal notranslate"><span class="pre">path</span></code> checks if the uesr provided path is inside the working directory. If not the query is not executed. <code class="docutils literal notranslate"><span class="pre">enum</span></code> is a list of allowed search terms. If the user submits something which is not included in the list, the query returns an error.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">query_enum</span></code>: A list containing allowed search terms if <code class="docutils literal notranslate"><span class="pre">query_type</span></code> is set to <code class="docutils literal notranslate"><span class="pre">enum</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">working_dir</span></code>: The directory where the command has to be executed. Default: <code class="docutils literal notranslate"><span class="pre">.</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">result_separator</span></code>: The character that separates results. Default: <code class="docutils literal notranslate"><span class="pre">\n</span></code></p></li>
</ul>
<p>The example engine below can be used to find files with a specific name in the configured
working directory.</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">find</span><span class="w"></span>
<span class="w"> </span><span class="nt">engine</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">command</span><span class="w"></span>
<span class="w"> </span><span class="nt">command</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">[</span><span class="s">&#39;find&#39;</span><span class="p p-Indicator">,</span><span class="w"> </span><span class="s">&#39;.&#39;</span><span class="p p-Indicator">,</span><span class="w"> </span><span class="s">&#39;-name&#39;</span><span class="p p-Indicator">,</span><span class="w"> </span><span class="s">&#39;{{QUERY}}&#39;</span><span class="p p-Indicator">]</span><span class="w"></span>
<span class="w"> </span><span class="nt">query_type</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">path</span><span class="w"></span>
<span class="w"> </span><span class="nt">shortcut</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">fnd</span><span class="w"></span>
<span class="w"> </span><span class="nt">delimiter</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="nt">chars</span><span class="p">:</span><span class="w"> </span><span class="s">&#39;</span><span class="nv"> </span><span class="s">&#39;</span><span class="w"></span>
<span class="w"> </span><span class="nt">keys</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">[</span><span class="s">&#39;line&#39;</span><span class="p p-Indicator">]</span><span class="w"></span>
</pre></div>
</div>
</section>
<section id="next-steps">
<h2>Next steps<a class="headerlink" href="#next-steps" title="Permalink to this heading"></a></h2>
<p>In the next milestone, support for local search engines and indexers (e.g. Elasticsearch)
are going to be added. This way, you will be able to query your own databases/indexers.</p>
</section>
<section id="acknowledgement">
<h2>Acknowledgement<a class="headerlink" href="#acknowledgement" title="Permalink to this heading"></a></h2>
<p>This development was sponsored by <a class="reference external" href="https://nlnet.nl/discovery">Search and Discovery Fund</a> of <a class="reference external" href="https://nlnet.nl/">NLnet Foundation</a> .</p>
<div class="line-block">
<div class="line">Happy hacking.</div>
<div class="line">kvch // 2020.09.28 21:26</div>
</div>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<span id="sidebar-top"></span>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../index.html">
<img class="logo" src="../_static/searx_logo_small.png" alt="Logo"/>
</a></p>
<h3>Project Links</h3>
<ul>
<li><a href="https://searx.github.io/searx/blog/index.html">Blog</a>
<li><a href="https://github.com/searx/searx">Source</a>
<li><a href="https://github.com/searx/searx/wiki">Wiki</a>
<li><a href="https://twitter.com/Searx_engine">Twitter</a>
<li><a href="https://github.com/searx/searx/issues">Issue Tracker</a>
</ul><h3>Navigation</h3>
<ul>
<li><a href="../index.html">Overview</a>
<ul>
<li><a href="index.html">Blog</a>
<ul>
<li>Previous: <a href="search-indexer-engines.html" title="previous chapter">Query your local search engines</a>
<li>Next: <a href="lxcdev-202006.html" title="next chapter">Developing in Linux containers [202006]</a></ul>
</li>
</ul>
</li>
</ul>
<div 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>
</div>
<script>document.getElementById('searchbox').style.display = "block"</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2015-2022, Adam Tauber, Noémi Ványi.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
<script src="../_static/version_warning_offset.js"></script>
</body>
</html>