.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.answerers._core.AnswerStorage Class Reference
+ Inheritance diagram for searx.answerers._core.AnswerStorage:
+ Collaboration diagram for searx.answerers._core.AnswerStorage:

Public Member Functions

 __init__ (self)
 
 load_builtins (self)
 
 register_by_fqn (self, str fqn)
 
 register (self, Answerer answerer)
 
list[BaseAnswerask (self, str query)
 
list[AnswererInfoinfo (self)
 

Static Public Attributes

set answerer_list [Answerer]
 

Detailed Description

A storage for managing the *answerers* of SearXNG.  With the
:py:obj:`AnswerStorage.ask`” method, a caller can ask questions to all
*answerers* and receives a list of the results.

Definition at line 88 of file _core.py.

Constructor & Destructor Documentation

◆ __init__()

searx.answerers._core.AnswerStorage.__init__ ( self)

Definition at line 96 of file _core.py.

96 def __init__(self):
97 super().__init__()
98 self.answerer_list = set()
99

References __init__(), and answerer_list.

Referenced by __init__().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Function Documentation

◆ ask()

list[BaseAnswer] searx.answerers._core.AnswerStorage.ask ( self,
str query )
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.

Definition at line 144 of file _core.py.

144 def ask(self, query: str) -> list[BaseAnswer]:
145 """An answerer is identified via keywords, if there is a keyword at the
146 first position in the ``query`` for which there is one or more
147 answerers, then these are called, whereby the entire ``query`` is passed
148 as argument to the answerer function."""
149
150 results = []
151 keyword = None
152 for keyword in query.split():
153 if keyword:
154 break
155
156 if not keyword or keyword not in self:
157 return results
158
159 for answerer in self[keyword]:
160 for answer in answerer.answer(query):
161 # In case of *answers* prefix ``answerer:`` is set, see searx.result_types.Result
162 answer.engine = f"answerer: {keyword}"
163 results.append(answer)
164
165 return results
166

◆ info()

list[AnswererInfo] searx.answerers._core.AnswerStorage.info ( self)

Definition at line 168 of file _core.py.

168 def info(self) -> list[AnswererInfo]:
169 return [a.info() for a in self.answerer_list]

References answerer_list.

◆ load_builtins()

searx.answerers._core.AnswerStorage.load_builtins ( self)
Loads ``answerer.py`` modules from the python packages in
:origin:`searx/answerers`.  The python modules are wrapped by
:py:obj:`ModuleAnswerer`.

Definition at line 100 of file _core.py.

100 def load_builtins(self):
101 """Loads ``answerer.py`` modules from the python packages in
102 :origin:`searx/answerers`. The python modules are wrapped by
103 :py:obj:`ModuleAnswerer`."""
104
105 for f in _default.iterdir():
106 if f.name.startswith("_"):
107 continue
108
109 if f.is_file() and f.suffix == ".py":
110 self.register_by_fqn(f"searx.answerers.{f.stem}.SXNGAnswerer")
111 continue
112
113 # for backward compatibility (if a fork has additional answerers)
114
115 if f.is_dir() and (f / "answerer.py").exists():
116 warnings.warn(
117 f"answerer module {f} is deprecated / migrate to searx.answerers.Answerer", DeprecationWarning
118 )
119 mod = load_module("answerer.py", str(f))
120 self.register(ModuleAnswerer(mod))
121

References register(), and register_by_fqn().

+ Here is the call graph for this function:

◆ register()

searx.answerers._core.AnswerStorage.register ( self,
Answerer answerer )
Register a :py:obj:`Answerer`.

Definition at line 136 of file _core.py.

136 def register(self, answerer: Answerer):
137 """Register a :py:obj:`Answerer`."""
138
139 self.answerer_list.add(answerer)
140 for _kw in answerer.keywords:
141 self[_kw] = self.get(_kw, [])
142 self[_kw].append(answerer)
143

References answerer_list, searx.botdetection.config.Config.get(), searx.metrics.models.CounterStorage.get(), searx.metrics.models.HistogramStorage.get(), and searx.network.Request.get().

Referenced by load_builtins(), searx.plugins._core.PluginStorage.load_builtins(), register_by_fqn(), and searx.plugins._core.PluginStorage.register_by_fqn().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ register_by_fqn()

searx.answerers._core.AnswerStorage.register_by_fqn ( self,
str fqn )
Register a :py:obj:`Answerer` via its fully qualified class namen(FQN).

Definition at line 122 of file _core.py.

122 def register_by_fqn(self, fqn: str):
123 """Register a :py:obj:`Answerer` via its fully qualified class namen(FQN)."""
124
125 mod_name, _, obj_name = fqn.rpartition('.')
126 mod = importlib.import_module(mod_name)
127 code_obj = getattr(mod, obj_name, None)
128
129 if code_obj is None:
130 msg = f"answerer {fqn} is not implemented"
131 log.critical(msg)
132 raise ValueError(msg)
133
134 self.register(code_obj())
135

References register().

Referenced by load_builtins(), and searx.plugins._core.PluginStorage.load_builtins().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ answerer_list

set searx.answerers._core.AnswerStorage.answerer_list [Answerer]
static

Definition at line 93 of file _core.py.

Referenced by __init__(), info(), and register().


The documentation for this class was generated from the following file: