plugins.rst.txt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. .. _dev plugin:
  2. =======
  3. Plugins
  4. =======
  5. .. sidebar:: Further reading ..
  6. - :ref:`plugins generic`
  7. Plugins can extend or replace functionality of various components of searx.
  8. Example plugin
  9. ==============
  10. .. code:: python
  11. name = 'Example plugin'
  12. description = 'This plugin extends the suggestions with the word "example"'
  13. default_on = False # disabled by default
  14. js_dependencies = tuple() # optional, list of static js files
  15. css_dependencies = tuple() # optional, list of static css files
  16. # attach callback to the post search hook
  17. # request: flask request object
  18. # ctx: the whole local context of the post search hook
  19. def post_search(request, ctx):
  20. ctx['search'].suggestions.add('example')
  21. return True
  22. External plugins
  23. ================
  24. External plugins are standard python modules implementing all the requirements of the standard plugins.
  25. Plugins can be enabled by adding them to :ref:`settings.yml`'s ``plugins`` section.
  26. Example external plugin can be found `here <https://github.com/asciimoo/searx_external_plugin_example>`_.
  27. Register your plugin
  28. ====================
  29. To enable your plugin register your plugin in
  30. searx > plugin > __init__.py.
  31. And at the bottom of the file add your plugin like.
  32. ``plugins.register(name_of_python_file)``
  33. Plugin entry points
  34. ===================
  35. Entry points (hooks) define when a plugin runs. Right now only three hooks are
  36. implemented. So feel free to implement a hook if it fits the behaviour of your
  37. plugin.
  38. Pre search hook
  39. ---------------
  40. Runs BEFORE the search request. Function to implement: ``pre_search``
  41. Post search hook
  42. ----------------
  43. Runs AFTER the search request. Function to implement: ``post_search``
  44. Result hook
  45. -----------
  46. Runs when a new result is added to the result list. Function to implement:
  47. ``on_result``