.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 87 of file _core.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 95 of file _core.py.

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

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 143 of file _core.py.

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

◆ info()

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

Definition at line 167 of file _core.py.

167 def info(self) -> list[AnswererInfo]:
168 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 99 of file _core.py.

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

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 135 of file _core.py.

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

References answerer_list, searx.botdetection.config.Config.get(), searx.cache.ExpireCache.get(), searx.cache.ExpireCacheSQLite.get(), searx.enginelib.EngineCache.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_settings(), and 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 121 of file _core.py.

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

References register().

Referenced by 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 92 of file _core.py.

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


The documentation for this class was generated from the following file:
  • /home/andrew/Documents/code/public/searxng/searx/answerers/_core.py