plugins.html 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <title>Plugins &#8212; Searx Documentation (Searx-1.1.0.tex)</title>
  8. <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
  9. <link rel="stylesheet" type="text/css" href="../_static/searx.css" />
  10. <link rel="stylesheet" type="text/css" href="../_static/tabs.css" />
  11. <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
  12. <script src="../_static/jquery.js"></script>
  13. <script src="../_static/underscore.js"></script>
  14. <script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
  15. <script src="../_static/doctools.js"></script>
  16. <script src="../_static/sphinx_highlight.js"></script>
  17. <link rel="index" title="Index" href="../genindex.html" />
  18. <link rel="search" title="Search" href="../search.html" />
  19. <link rel="next" title="Translation" href="translation.html" />
  20. <link rel="prev" title="Search API" href="search_api.html" />
  21. </head><body>
  22. <div class="related" role="navigation" aria-label="related navigation">
  23. <h3>Navigation</h3>
  24. <ul>
  25. <li class="right" style="margin-right: 10px">
  26. <a href="../genindex.html" title="General Index"
  27. accesskey="I">index</a></li>
  28. <li class="right" >
  29. <a href="../py-modindex.html" title="Python Module Index"
  30. >modules</a> |</li>
  31. <li class="right" >
  32. <a href="translation.html" title="Translation"
  33. accesskey="N">next</a> |</li>
  34. <li class="right" >
  35. <a href="search_api.html" title="Search API"
  36. accesskey="P">previous</a> |</li>
  37. <li class="nav-item nav-item-0"><a href="../index.html">Searx Documentation (Searx-1.1.0.tex)</a> &#187;</li>
  38. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Developer documentation</a> &#187;</li>
  39. <li class="nav-item nav-item-this"><a href="">Plugins</a></li>
  40. </ul>
  41. </div>
  42. <div class="document">
  43. <div class="documentwrapper">
  44. <div class="bodywrapper">
  45. <div class="body" role="main">
  46. <section id="plugins">
  47. <span id="dev-plugin"></span><h1>Plugins<a class="headerlink" href="#plugins" title="Permalink to this heading">¶</a></h1>
  48. <aside class="sidebar">
  49. <p class="sidebar-title">Further reading ..</p>
  50. <ul class="simple">
  51. <li><p><a class="reference internal" href="../admin/plugins.html#plugins-generic"><span class="std std-ref">Plugins builtin</span></a></p></li>
  52. </ul>
  53. </aside>
  54. <p>Plugins can extend or replace functionality of various components of searx.</p>
  55. <section id="example-plugin">
  56. <h2>Example plugin<a class="headerlink" href="#example-plugin" title="Permalink to this heading">¶</a></h2>
  57. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;Example plugin&#39;</span>
  58. <span class="n">description</span> <span class="o">=</span> <span class="s1">&#39;This plugin extends the suggestions with the word &quot;example&quot;&#39;</span>
  59. <span class="n">default_on</span> <span class="o">=</span> <span class="kc">False</span> <span class="c1"># disabled by default</span>
  60. <span class="n">js_dependencies</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">()</span> <span class="c1"># optional, list of static js files</span>
  61. <span class="n">css_dependencies</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">()</span> <span class="c1"># optional, list of static css files</span>
  62. <span class="c1"># attach callback to the post search hook</span>
  63. <span class="c1"># request: flask request object</span>
  64. <span class="c1"># ctx: the whole local context of the post search hook</span>
  65. <span class="k">def</span> <span class="nf">post_search</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">ctx</span><span class="p">):</span>
  66. <span class="n">ctx</span><span class="p">[</span><span class="s1">&#39;search&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">suggestions</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;example&#39;</span><span class="p">)</span>
  67. <span class="k">return</span> <span class="kc">True</span>
  68. </pre></div>
  69. </div>
  70. </section>
  71. <section id="external-plugins">
  72. <h2>External plugins<a class="headerlink" href="#external-plugins" title="Permalink to this heading">¶</a></h2>
  73. <p>External plugins are standard python modules implementing all the requirements of the standard plugins.
  74. Plugins can be enabled by adding them to <a class="reference internal" href="../admin/settings.html#settings-yml"><span class="std std-ref">settings.yml</span></a>’s <code class="docutils literal notranslate"><span class="pre">plugins</span></code> section.
  75. Example external plugin can be found <a class="reference external" href="https://github.com/asciimoo/searx_external_plugin_example">here</a>.</p>
  76. </section>
  77. <section id="register-your-plugin">
  78. <h2>Register your plugin<a class="headerlink" href="#register-your-plugin" title="Permalink to this heading">¶</a></h2>
  79. <p>To enable your plugin register your plugin in
  80. searx &gt; plugin &gt; __init__.py.
  81. And at the bottom of the file add your plugin like.
  82. <code class="docutils literal notranslate"><span class="pre">plugins.register(name_of_python_file)</span></code></p>
  83. </section>
  84. <section id="plugin-entry-points">
  85. <h2>Plugin entry points<a class="headerlink" href="#plugin-entry-points" title="Permalink to this heading">¶</a></h2>
  86. <p>Entry points (hooks) define when a plugin runs. Right now only three hooks are
  87. implemented. So feel free to implement a hook if it fits the behaviour of your
  88. plugin.</p>
  89. <section id="pre-search-hook">
  90. <h3>Pre search hook<a class="headerlink" href="#pre-search-hook" title="Permalink to this heading">¶</a></h3>
  91. <p>Runs BEFORE the search request. Function to implement: <code class="docutils literal notranslate"><span class="pre">pre_search</span></code></p>
  92. </section>
  93. <section id="post-search-hook">
  94. <h3>Post search hook<a class="headerlink" href="#post-search-hook" title="Permalink to this heading">¶</a></h3>
  95. <p>Runs AFTER the search request. Function to implement: <code class="docutils literal notranslate"><span class="pre">post_search</span></code></p>
  96. </section>
  97. <section id="result-hook">
  98. <h3>Result hook<a class="headerlink" href="#result-hook" title="Permalink to this heading">¶</a></h3>
  99. <p>Runs when a new result is added to the result list. Function to implement:
  100. <code class="docutils literal notranslate"><span class="pre">on_result</span></code></p>
  101. </section>
  102. </section>
  103. </section>
  104. <div class="clearer"></div>
  105. </div>
  106. </div>
  107. </div>
  108. <span id="sidebar-top"></span>
  109. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  110. <div class="sphinxsidebarwrapper">
  111. <p class="logo"><a href="../index.html">
  112. <img class="logo" src="../_static/searx_logo_small.png" alt="Logo"/>
  113. </a></p>
  114. <h3>Project Links</h3>
  115. <ul>
  116. <li><a href="https://searx.github.io/searx/blog/index.html">Blog</a>
  117. <li><a href="https://github.com/searx/searx">Source</a>
  118. <li><a href="https://github.com/searx/searx/wiki">Wiki</a>
  119. <li><a href="https://twitter.com/Searx_engine">Twitter</a>
  120. <li><a href="https://github.com/searx/searx/issues">Issue Tracker</a>
  121. </ul><h3>Navigation</h3>
  122. <ul>
  123. <li><a href="../index.html">Overview</a>
  124. <ul>
  125. <li><a href="index.html">Developer documentation</a>
  126. <ul>
  127. <li>Previous: <a href="search_api.html" title="previous chapter">Search API</a>
  128. <li>Next: <a href="translation.html" title="next chapter">Translation</a></ul>
  129. </li>
  130. </ul>
  131. </li>
  132. </ul>
  133. <div id="searchbox" style="display: none" role="search">
  134. <h3 id="searchlabel">Quick search</h3>
  135. <div class="searchformwrapper">
  136. <form class="search" action="../search.html" method="get">
  137. <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
  138. <input type="submit" value="Go" />
  139. </form>
  140. </div>
  141. </div>
  142. <script>document.getElementById('searchbox').style.display = "block"</script>
  143. </div>
  144. </div>
  145. <div class="clearer"></div>
  146. </div>
  147. <div class="footer" role="contentinfo">
  148. &#169; Copyright 2015-2022, Adam Tauber, Noémi Ványi.
  149. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
  150. </div>
  151. <script src="../_static/version_warning_offset.js"></script>
  152. </body>
  153. </html>