plugins.rst 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. Plugins
  2. -------
  3. Plugins can extend/replace functionality of various components inside
  4. searx.
  5. example\_plugin.py
  6. ~~~~~~~~~~~~~~~~~~
  7. .. code:: python
  8. name = 'Example plugin'
  9. description = 'This plugin extends the suggestions with the word "example"'
  10. default_on = False # disable by default
  11. js_dependencies = tuple() # optional, list of static js files
  12. css_dependencies = tuple() # optional, list of static css files
  13. # attach callback to the post search hook
  14. # request: flask request object
  15. # ctx: the whole local context of the post search hook
  16. def post_search(request, ctx):
  17. ctx['search'].suggestions.add('example')
  18. return True
  19. Currently implemented plugin entry points (a.k.a hooks)
  20. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  21. - Pre search hook (``pre_search``)
  22. - Post search hook (``post_search``)
  23. - Result hook (``on_result``) (is called if a new result is added (see
  24. https\_rewrite plugin))
  25. Feel free to add more hooks to the code if it is required by a plugin.
  26. TODO
  27. ~~~~
  28. - Better documentation
  29. - More hooks
  30. - search hook (is called while searx is requesting results (for
  31. example: things like math-solver), the different hooks are running
  32. parallel)