.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.enginelib.traits.EngineTraitsMap Class Reference
+ Inheritance diagram for searx.enginelib.traits.EngineTraitsMap:
+ Collaboration diagram for searx.enginelib.traits.EngineTraitsMap:

Public Member Functions

 save_data (self)
 
'EngineTraitsMapfrom_data (cls)
 
'EngineTraitsMapfetch_traits (cls, Callable log)
 
 set_traits (self, Engine|types.ModuleType engine)
 
- Public Member Functions inherited from searx.enginelib.traits.EngineTraits
 get_language (self, str searxng_locale, default=None)
 
 get_region (self, str searxng_locale, default=None)
 
bool is_locale_supported (self, str searxng_locale)
 
 copy (self)
 

Static Public Attributes

tuple ENGINE_TRAITS_FILE = (data_dir / 'engine_traits.json').resolve()
 
- Static Public Attributes inherited from searx.enginelib.traits.EngineTraits
Dict regions = dataclasses.field(default_factory=dict)
 
Dict languages = dataclasses.field(default_factory=dict)
 
Optional all_locale = None
 
Literal data_type = 'traits_v1'
 
Dict custom = dataclasses.field(default_factory=dict)
 

Additional Inherited Members

- Public Attributes inherited from searx.enginelib.traits.EngineTraits
str data_type = 'traits_v1':
 
- Protected Member Functions inherited from searx.enginelib.traits.EngineTraits
 _set_traits_v1 (self, Engine engine)
 

Detailed Description

A python dictionary to map :class:`EngineTraits` by engine name.

Definition at line 193 of file traits.py.

Member Function Documentation

◆ fetch_traits()

'EngineTraitsMap' searx.enginelib.traits.EngineTraitsMap.fetch_traits ( cls,
Callable engine )
Call a function ``fetch_traits(engine_traits)`` from engines namespace to fetch
and set properties from the origin engine in the object ``engine_traits``.  If
function does not exists, ``None`` is returned.

Reimplemented from searx.enginelib.traits.EngineTraits.

Definition at line 213 of file traits.py.

213 def fetch_traits(cls, log: Callable) -> 'EngineTraitsMap':
214 from searx import engines # pylint: disable=cyclic-import, import-outside-toplevel
215
216 names = list(engines.engines)
217 names.sort()
218 obj = cls()
219
220 for engine_name in names:
221 engine = engines.engines[engine_name]
222
223 traits = EngineTraits.fetch_traits(engine)
224 if traits is not None:
225 log("%-20s: SearXNG languages --> %s " % (engine_name, len(traits.languages)))
226 log("%-20s: SearXNG regions --> %s" % (engine_name, len(traits.regions)))
227 obj[engine_name] = traits
228
229 return obj
230

◆ from_data()

'EngineTraitsMap' searx.enginelib.traits.EngineTraitsMap.from_data ( cls)
Instantiate :class:`EngineTraitsMap` object from :py:obj:`ENGINE_TRAITS`

Definition at line 205 of file traits.py.

205 def from_data(cls) -> 'EngineTraitsMap':
206 """Instantiate :class:`EngineTraitsMap` object from :py:obj:`ENGINE_TRAITS`"""
207 obj = cls()
208 for k, v in ENGINE_TRAITS.items():
209 obj[k] = EngineTraits(**v)
210 return obj
211

◆ save_data()

searx.enginelib.traits.EngineTraitsMap.save_data ( self)
Store EngineTraitsMap in in file :py:obj:`self.ENGINE_TRAITS_FILE`

Definition at line 199 of file traits.py.

199 def save_data(self):
200 """Store EngineTraitsMap in in file :py:obj:`self.ENGINE_TRAITS_FILE`"""
201 with open(self.ENGINE_TRAITS_FILE, 'w', encoding='utf-8') as f:
202 json.dump(self, f, indent=2, sort_keys=True, cls=EngineTraitsEncoder)
203

References searx.enginelib.traits.EngineTraitsMap.ENGINE_TRAITS_FILE.

◆ set_traits()

searx.enginelib.traits.EngineTraitsMap.set_traits ( self,
Engine | types.ModuleType engine )
Set traits in a :py:obj:`Engine` namespace.

:param engine: engine instance build by :py:func:`searx.engines.load_engine`

Reimplemented from searx.enginelib.traits.EngineTraits.

Definition at line 231 of file traits.py.

231 def set_traits(self, engine: Engine | types.ModuleType):
232 """Set traits in a :py:obj:`Engine` namespace.
233
234 :param engine: engine instance build by :py:func:`searx.engines.load_engine`
235 """
236
237 engine_traits = EngineTraits(data_type='traits_v1')
238 if engine.name in self.keys():
239 engine_traits = self[engine.name]
240
241 elif engine.engine in self.keys():
242 # The key of the dictionary traits_map is the *engine name*
243 # configured in settings.xml. When multiple engines are configured
244 # in settings.yml to use the same origin engine (python module)
245 # these additional engines can use the languages from the origin
246 # engine. For this use the configured ``engine: ...`` from
247 # settings.yml
248 engine_traits = self[engine.engine]
249
250 engine_traits.set_traits(engine)

Member Data Documentation

◆ ENGINE_TRAITS_FILE

searx.enginelib.traits.EngineTraitsMap.ENGINE_TRAITS_FILE = (data_dir / 'engine_traits.json').resolve()
static

Definition at line 196 of file traits.py.

Referenced by searx.enginelib.traits.EngineTraitsMap.save_data().


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