plugins.rst 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. Register your plugin
  23. ====================
  24. To enable your plugin register your plugin in
  25. searx > plugin > __init__.py.
  26. And at the bottom of the file add your plugin like.
  27. ``plugins.register(name_of_python_file)``
  28. Plugin entry points
  29. ===================
  30. Entry points (hooks) define when a plugin runs. Right now only three hooks are
  31. implemented. So feel free to implement a hook if it fits the behaviour of your
  32. plugin.
  33. Pre search hook
  34. ---------------
  35. Runs BEFORE the search request. Function to implement: ``pre_search``
  36. Post search hook
  37. ----------------
  38. Runs AFTER the search request. Function to implement: ``post_search``
  39. Result hook
  40. -----------
  41. Runs when a new result is added to the result list. Function to implement:
  42. ``on_result``