plugins.rst 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. Plugin entry points
  23. ===================
  24. Entry points (hooks) define when a plugin runs. Right now only three hooks are
  25. implemented. So feel free to implement a hook if it fits the behaviour of your
  26. plugin.
  27. Pre search hook
  28. ---------------
  29. Runs BEFORE the search request. Function to implement: ``pre_search``
  30. Post search hook
  31. ----------------
  32. Runs AFTER the search request. Function to implement: ``post_search``
  33. Result hook
  34. -----------
  35. Runs when a new result is added to the result list. Function to implement:
  36. ``on_result``