.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.query.BangParser Class Reference
+ Inheritance diagram for searx.query.BangParser:
+ Collaboration diagram for searx.query.BangParser:

Public Member Functions

 __call__ (self, raw_value)
 
- Public Member Functions inherited from searx.query.QueryPartParser
 __init__ (self, raw_text_query, enable_autocomplete)
 

Static Public Member Functions

 check (raw_value)
 
- Static Public Member Functions inherited from searx.query.QueryPartParser

Public Attributes

 enable_autocomplete
 
- Public Attributes inherited from searx.query.QueryPartParser
 raw_text_query = raw_text_query
 
 enable_autocomplete = enable_autocomplete
 

Protected Member Functions

 _parse (self, value)
 
 _autocomplete (self, first_char, value)
 
- Protected Member Functions inherited from searx.query.QueryPartParser
 _add_autocomplete (self, value)
 

Detailed Description

Definition at line 179 of file query.py.

Member Function Documentation

◆ __call__()

searx.query.BangParser.__call__ ( self,
raw_value )
Try to parse raw_value: set the self.raw_text_query properties

return True if raw_value has been parsed

self.raw_text_query.autocomplete_list is also modified
if self.enable_autocomplete is True

Reimplemented from searx.query.QueryPartParser.

Definition at line 185 of file query.py.

185 def __call__(self, raw_value):
186 value = raw_value[1:].replace('-', ' ').replace('_', ' ')
187 found = self._parse(value) if len(value) > 0 else False
188 if found and raw_value[0] == '!':
189 self.raw_text_query.specific = True
190 if self.enable_autocomplete:
191 self._autocomplete(raw_value[0], value)
192 return found
193

References searx.query.BangParser._parse(), searx.query.ExternalBangParser._parse(), searx.query.LanguageParser._parse(), searx.query.TimeoutParser._parse(), and searx.query.QueryPartParser.raw_text_query.

+ Here is the call graph for this function:

◆ _autocomplete()

searx.query.BangParser._autocomplete ( self,
first_char,
value )
protected

Definition at line 217 of file query.py.

217 def _autocomplete(self, first_char, value):
218 if not value:
219 # show some example queries
220 for suggestion in ['images', 'wikipedia', 'osm']:
221 if suggestion not in self.raw_text_query.disabled_engines or suggestion in categories:
222 self._add_autocomplete(first_char + suggestion)
223 return
224
225 # check if query starts with category name
226 for category in categories:
227 if category.startswith(value):
228 self._add_autocomplete(first_char + category.replace(' ', '_'))
229
230 # check if query starts with engine name
231 for engine in engines:
232 if engine.startswith(value):
233 self._add_autocomplete(first_char + engine.replace(' ', '_'))
234
235 # check if query starts with engine shortcut
236 for engine_shortcut in engine_shortcuts:
237 if engine_shortcut.startswith(value):
238 self._add_autocomplete(first_char + engine_shortcut)
239
240

References searx.query.QueryPartParser._add_autocomplete(), and searx.query.QueryPartParser.raw_text_query.

Referenced by searx.query.LanguageParser.__call__(), and searx.query.TimeoutParser.__call__().

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

◆ _parse()

searx.query.BangParser._parse ( self,
value )
protected

Definition at line 194 of file query.py.

194 def _parse(self, value):
195 # check if prefix is equal with engine shortcut
196 if value in engine_shortcuts: # pylint: disable=consider-using-get
197 value = engine_shortcuts[value]
198
199 # check if prefix is equal with engine name
200 if value in engines:
201 self.raw_text_query.enginerefs.append(EngineRef(value, 'none'))
202 return True
203
204 # check if prefix is equal with category name
205 if value in categories:
206 # using all engines for that search, which
207 # are declared under that category name
208 self.raw_text_query.enginerefs.extend(
209 EngineRef(engine.name, value)
210 for engine in categories[value]
211 if (engine.name, value) not in self.raw_text_query.disabled_engines
212 )
213 return True
214
215 return False
216

References searx.query.QueryPartParser.raw_text_query.

Referenced by searx.query.BangParser.__call__(), searx.query.ExternalBangParser.__call__(), searx.query.LanguageParser.__call__(), and searx.query.TimeoutParser.__call__().

+ Here is the caller graph for this function:

◆ check()

searx.query.BangParser.check ( raw_value)
static
Check if raw_value can be parsed

Reimplemented from searx.query.QueryPartParser.

Definition at line 181 of file query.py.

181 def check(raw_value):
182 # make sure it's not any bang with double '!!'
183 return raw_value[0] == '!' and (len(raw_value) < 2 or raw_value[1] != '!')
184

Member Data Documentation

◆ enable_autocomplete

searx.query.BangParser.enable_autocomplete

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