.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.query.RawTextQuery Class Reference

Public Member Functions

 __init__ (self, str query, list disabled_engines)
 
 get_autocomplete_full_query (self, text)
 
 changeQuery (self, query)
 
 getQuery (self)
 
 getFullQuery (self)
 
 __str__ (self)
 
 __repr__ (self)
 

Public Attributes

 query = query
 
 disabled_engines = disabled_engines if disabled_engines else []
 
list enginerefs = []
 
list languages = []
 
 timeout_limit = None
 
 external_bang = None
 
bool specific = False
 
list autocomplete_list = []
 
list query_parts = []
 
list user_query_parts = []
 
tuple autocomplete_location = None
 
bool redirect_to_first_result = False
 

Static Public Attributes

list PARSER_CLASSES
 

Protected Member Functions

 _parse_query (self)
 

Detailed Description

parse raw text query (the value from the html input)

Definition at line 251 of file query.py.

Constructor & Destructor Documentation

◆ __init__()

searx.query.RawTextQuery.__init__ ( self,
str query,
list disabled_engines )

Definition at line 262 of file query.py.

262 def __init__(self, query: str, disabled_engines: list):
263 assert isinstance(query, str)
264 # input parameters
265 self.query = query
266 self.disabled_engines = disabled_engines if disabled_engines else []
267 # parsed values
268 self.enginerefs = []
269 self.languages = []
270 self.timeout_limit = None
271 self.external_bang = None
272 self.specific = False
273 self.autocomplete_list = []
274 # internal properties
275 self.query_parts = [] # use self.getFullQuery()
276 self.user_query_parts = [] # use self.getQuery()
277 self.autocomplete_location = None
278 self.redirect_to_first_result = False
279 self._parse_query()
280

Member Function Documentation

◆ __repr__()

searx.query.RawTextQuery.__repr__ ( self)

Definition at line 336 of file query.py.

336 def __repr__(self):
337 return (
338 f"<{self.__class__.__name__} "
339 + f"query={self.query!r} "
340 + f"disabled_engines={self.disabled_engines!r}\n "
341 + f"languages={self.languages!r} "
342 + f"timeout_limit={self.timeout_limit!r} "
343 + f"external_bang={self.external_bang!r} "
344 + f"specific={self.specific!r} "
345 + f"enginerefs={self.enginerefs!r}\n "
346 + f"autocomplete_list={self.autocomplete_list!r}\n "
347 + f"query_parts={self.query_parts!r}\n "
348 + f"user_query_parts={self.user_query_parts!r} >\n"
349 + f"redirect_to_first_result={self.redirect_to_first_result!r}"
350 )

◆ __str__()

searx.query.RawTextQuery.__str__ ( self)

Definition at line 333 of file query.py.

333 def __str__(self):
334 return self.getFullQuery()
335

References searx.query.RawTextQuery.getFullQuery().

+ Here is the call graph for this function:

◆ _parse_query()

searx.query.RawTextQuery._parse_query ( self)
protected
parse self.query, if tags are set, which
change the search engine or search-language

Definition at line 281 of file query.py.

281 def _parse_query(self):
282 """
283 parse self.query, if tags are set, which
284 change the search engine or search-language
285 """
286
287 # split query, including whitespaces
288 raw_query_parts = re.split(r'(\s+)', self.query)
289
290 last_index_location = None
291 autocomplete_index = len(raw_query_parts) - 1
292
293 for i, query_part in enumerate(raw_query_parts):
294 # part does only contain spaces, skip
295 if query_part.isspace() or query_part == '':
296 continue
297
298 # parse special commands
299 special_part = False
300 for parser_class in RawTextQuery.PARSER_CLASSES:
301 if parser_class.check(query_part):
302 special_part = parser_class(self, i == autocomplete_index)(query_part)
303 break
304
305 # append query part to query_part list
306 qlist = self.query_parts if special_part else self.user_query_parts
307 qlist.append(query_part)
308 last_index_location = (qlist, len(qlist) - 1)
309
310 self.autocomplete_location = last_index_location
311

References searx.query.RawTextQuery.autocomplete_location, searx.query.RawTextQuery.query, searx.search.models.SearchQuery.query, searx.query.RawTextQuery.query_parts, and searx.query.RawTextQuery.user_query_parts.

◆ changeQuery()

searx.query.RawTextQuery.changeQuery ( self,
query )

Definition at line 317 of file query.py.

317 def changeQuery(self, query):
318 self.user_query_parts = query.strip().split()
319 self.query = self.getFullQuery()
320 self.autocomplete_location = (self.user_query_parts, len(self.user_query_parts) - 1)
321 self.autocomplete_list = []
322 return self
323

References searx.query.RawTextQuery.autocomplete_list, searx.query.RawTextQuery.autocomplete_location, searx.query.RawTextQuery.getFullQuery(), searx.query.RawTextQuery.query, searx.search.models.SearchQuery.query, and searx.query.RawTextQuery.user_query_parts.

+ Here is the call graph for this function:

◆ get_autocomplete_full_query()

searx.query.RawTextQuery.get_autocomplete_full_query ( self,
text )

Definition at line 312 of file query.py.

312 def get_autocomplete_full_query(self, text):
313 qlist, position = self.autocomplete_location
314 qlist[position] = text
315 return self.getFullQuery()
316

References searx.query.RawTextQuery.autocomplete_location, and searx.query.RawTextQuery.getFullQuery().

+ Here is the call graph for this function:

◆ getFullQuery()

searx.query.RawTextQuery.getFullQuery ( self)
get full query including whitespaces

Definition at line 327 of file query.py.

327 def getFullQuery(self):
328 """
329 get full query including whitespaces
330 """
331 return '{0} {1}'.format(' '.join(self.query_parts), self.getQuery()).strip()
332

References searx.format, searx.query.RawTextQuery.getQuery(), and searx.query.RawTextQuery.query_parts.

Referenced by searx.query.RawTextQuery.__str__(), searx.query.RawTextQuery.changeQuery(), and searx.query.RawTextQuery.get_autocomplete_full_query().

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

◆ getQuery()

searx.query.RawTextQuery.getQuery ( self)

Definition at line 324 of file query.py.

324 def getQuery(self):
325 return ' '.join(self.user_query_parts)
326

References searx.query.RawTextQuery.user_query_parts.

Referenced by searx.query.RawTextQuery.getFullQuery().

+ Here is the caller graph for this function:

Member Data Documentation

◆ autocomplete_list

list searx.query.RawTextQuery.autocomplete_list = []

Definition at line 273 of file query.py.

Referenced by searx.query.RawTextQuery.changeQuery().

◆ autocomplete_location

tuple searx.query.RawTextQuery.autocomplete_location = None

◆ disabled_engines

searx.query.RawTextQuery.disabled_engines = disabled_engines if disabled_engines else []

Definition at line 266 of file query.py.

◆ enginerefs

list searx.query.RawTextQuery.enginerefs = []

Definition at line 268 of file query.py.

◆ external_bang

◆ languages

◆ PARSER_CLASSES

list searx.query.RawTextQuery.PARSER_CLASSES
static
Initial value:
= [
TimeoutParser, # force the timeout
LanguageParser, # force a language
ExternalBangParser, # external bang (must be before BangParser)
BangParser, # force an engine or category
FeelingLuckyParser, # redirect to the first link in the results list
]

Definition at line 254 of file query.py.

◆ query

◆ query_parts

searx.query.RawTextQuery.query_parts = []

◆ redirect_to_first_result

bool searx.query.RawTextQuery.redirect_to_first_result = False

◆ specific

bool searx.query.RawTextQuery.specific = False

Definition at line 272 of file query.py.

◆ timeout_limit

◆ user_query_parts

searx.query.RawTextQuery.user_query_parts = []

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