command-line-engines.rst 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. .. _engine command:
  2. ====================
  3. Command Line Engines
  4. ====================
  5. .. sidebar:: info
  6. - :origin:`command.py <searx/engines/command.py>`
  7. - :ref:`offline engines`
  8. With *command engines* administrators can run engines to integrate arbitrary
  9. shell commands.
  10. When creating and enabling a ``command`` engine on a public instance, you must
  11. be careful to avoid leaking private data. The easiest solution is to limit the
  12. access by setting ``tokens`` as described in section :ref:`private engines`.
  13. The engine base is flexible. Only your imagination can limit the power of this
  14. engine (and maybe security concerns). The following options are available:
  15. ``command``:
  16. A comma separated list of the elements of the command. A special token
  17. ``{{QUERY}}`` tells where to put the search terms of the user. Example:
  18. .. code:: yaml
  19. ['ls', '-l', '-h', '{{QUERY}}']
  20. ``delimiter``:
  21. A mapping containing a delimiter ``char`` and the *titles* of each element in
  22. ``keys``.
  23. ``parse_regex``:
  24. A dict containing the regular expressions for each result key.
  25. ``query_type``:
  26. The expected type of user search terms. Possible values: ``path`` and
  27. ``enum``.
  28. ``path``:
  29. Checks if the user provided path is inside the working directory. If not,
  30. the query is not executed.
  31. ``enum``:
  32. Is a list of allowed search terms. If the user submits something which is
  33. not included in the list, the query returns an error.
  34. ``query_enum``:
  35. A list containing allowed search terms if ``query_type`` is set to ``enum``.
  36. ``working_dir``:
  37. The directory where the command has to be executed. Default: ``./``
  38. ``result_separator``:
  39. The character that separates results. Default: ``\n``
  40. The example engine below can be used to find files with a specific name in the
  41. configured working directory:
  42. .. code:: yaml
  43. - name: find
  44. engine: command
  45. command: ['find', '.', '-name', '{{QUERY}}']
  46. query_type: path
  47. shortcut: fnd
  48. delimiter:
  49. chars: ' '
  50. keys: ['line']
  51. Acknowledgment
  52. ==============
  53. This development was sponsored by `Search and Discovery Fund
  54. <https://nlnet.nl/discovery>`_ of `NLnet Foundation <https://nlnet.nl/>`_.