Answerer Development
The answerers give instant answers related to the search query, they
usually provide answers of type Answer.
Here is an example of a very simple answerer that adds a “Hello” into the answer area:
from flask_babel import gettext as _
from searx.answerers import Answerer
from searx.result_types import Answer
class MyAnswerer(Answerer):
keywords = [ "hello", "hello world" ]
def info(self):
return AnswererInfo(name=_("Hello"), description=_("lorem .."), keywords=self.keywords)
def answer(self, request, search):
return [ Answer(answer="Hello") ]
class searx.answerers.Answerer[source] : Abstract base class of answerers.
keywords: [list](https://docs.python.org/3/builtins/stdtypes.html#list)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)]
: Keywords to which the answerer has *answers*.
abstractmethod answer(*query: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*) → [list](https://docs.python.org/3/builtins/stdtypes.html#list)[[BaseAnswer](https://docs.searxng.org/dev/result_types/answer.html#searx.result_types.answer.BaseAnswer)][[source]](https://docs.searxng.org/_modules/searx/answerers/_core.html#Answerer.answer)
: Function that returns a list of answers to the question/query.
abstractmethod info() → [AnswererInfo](#searx.answerers.AnswererInfo)[[source]](https://docs.searxng.org/_modules/searx/answerers/_core.html#Answerer.info)
: Information about the *answerer*, see [`AnswererInfo`](#searx.answerers.AnswererInfo).
class searx.answerers.AnswererInfo(name: str, description: str, examples: list[str], keywords: list[str])[source] : Object that holds information about an answerer, these infos are shown to the user in the Preferences menu.
To be able to translate the information into other languages, the text must
be written in English and translated with [`flask_babel.gettext`](https://python-babel.github.io/flask-babel/index.html#flask_babel.gettext).
name: [str](https://docs.python.org/3/builtins/stdtypes.html#str)
: Name of the *answerer*.
description: [str](https://docs.python.org/3/builtins/stdtypes.html#str)
: Short description of the *answerer*.
examples: [list](https://docs.python.org/3/builtins/stdtypes.html#list)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)]
: List of short examples of the usage / of query terms.
keywords: [list](https://docs.python.org/3/builtins/stdtypes.html#list)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)]
: See [`Answerer.keywords`](#searx.answerers.Answerer.keywords)
class searx.answerers.AnswerStorage[source]
: A storage for managing the answerers of SearXNG. With the
AnswerStorage.ask” method, a caller can ask questions to all
answerers and receives a list of the results.
answerer\_list: [set](https://docs.python.org/3/builtins/stdtypes.html#set)[[Answerer](#searx.answerers.Answerer)]
: The list of [`Answerer`](#searx.answerers.Answerer) in this storage.
load\_builtins()[[source]](https://docs.searxng.org/_modules/searx/answerers/_core.html#AnswerStorage.load_builtins)
: Loads `answerer.py` modules from the python packages in
. The python modules are wrapped by
`ModuleAnswerer`.
register\_by\_fqn(*fqn: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*)[[source]](https://docs.searxng.org/_modules/searx/answerers/_core.html#AnswerStorage.register_by_fqn)
: Register a [`Answerer`](#searx.answerers.Answerer) via its fully qualified class namen(FQN).
register(*answerer: [Answerer](#searx.answerers.Answerer)*)[[source]](https://docs.searxng.org/_modules/searx/answerers/_core.html#AnswerStorage.register)
: Register a [`Answerer`](#searx.answerers.Answerer).
ask(*query: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*) → [list](https://docs.python.org/3/builtins/stdtypes.html#list)[[BaseAnswer](https://docs.searxng.org/dev/result_types/answer.html#searx.result_types.answer.BaseAnswer)][[source]](https://docs.searxng.org/_modules/searx/answerers/_core.html#AnswerStorage.ask)
: An answerer is identified via keywords, if there is a keyword at the
first position in the `query` for which there is one or more
answerers, then these are called, whereby the entire `query` is passed
as argument to the answerer function.
class searx.answerers._core.ModuleAnswerer(mod)[source]
: Bases: Answerer
A wrapper class for legacy *answerers* where the names (keywords, answer,
info) are implemented on the module level (not in a class).
#### Note
For internal use only!
answer(*query: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*) → [list](https://docs.python.org/3/builtins/stdtypes.html#list)[[BaseAnswer](https://docs.searxng.org/dev/result_types/answer.html#searx.result_types.answer.BaseAnswer)][[source]](https://docs.searxng.org/_modules/searx/answerers/_core.html#ModuleAnswerer.answer)
: Function that returns a list of answers to the question/query.
info() → [AnswererInfo](#searx.answerers.AnswererInfo)[[source]](https://docs.searxng.org/_modules/searx/answerers/_core.html#ModuleAnswerer.info)
: Information about the *answerer*, see [`AnswererInfo`](#searx.answerers.AnswererInfo).
Copyright © SearXNG team
Made with Furo
