searxng/searx/results/answer.py
Markus Heiser 069e1d7fb4 [mod] mudularize & document searx.results
The intention of this patch is to improve modularization & documentation of the
implementations about the *result* items.

  This patch does not contain any functional change!

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2022-08-06 19:09:45 +02:00

37 lines
923 B
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
# lint: pylint
"""Answer item in the result list. The answer result item is used in
the :origin:`results.html <searx/templates/simple/results.html>` template.
A answer item is a dictionary type with dedicated keys and values.
.. code:: python
results.append({
'answer' : str,
'url' : str,
})
answer : ``str``
The answer string append by the engine.
url : ``str``
A link that is related to the answer (e.g. the origin of the answer).
"""
def is_answer(result):
"""Returns ``True`` if result type is :py:obj:`.answer`, otherwise ``False``
In the result list a answer item is identified by the existence of the key
``answer``.
"""
return 'answer' in result
class Answers(dict):
"""Dictionary of answers in the :py:obj:`.container.ResultContainer`"""
def add(self, result):
self[result['answer']] = result