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.
- abstract answer(query: str) list[BaseAnswer] [source]¶
Function that returns a list of answers to the question/query.
- abstract info() AnswererInfo [source]¶
Informations about the answerer, see
AnswererInfo
.
- class searx.answerers.AnswererInfo(name: str, description: str, examples: list[str], keywords: list[str])[source]¶
Object that holds informations 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
.
- 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.- load_builtins()[source]¶
Loads
answerer.py
modules from the python packages in git://searx/answerers. The python modules are wrapped byModuleAnswerer
.
- ask(query: str) list[BaseAnswer] [source]¶
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 entirequery
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) list[BaseAnswer] [source]¶
Function that returns a list of answers to the question/query.
- info() AnswererInfo [source]¶
Informations about the answerer, see
AnswererInfo
.