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

Public Member Functions

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

Public Attributes

 query
 
 disabled_engines
 
 enginerefs
 
 languages
 
 timeout_limit
 
 external_bang
 
 specific
 
 autocomplete_list
 
 query_parts
 
 user_query_parts
 
 autocomplete_location
 
 redirect_to_first_result
 

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 250 of file query.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 261 of file query.py.

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

Member Function Documentation

◆ __repr__()

searx.query.RawTextQuery.__repr__ ( self)

Definition at line 335 of file query.py.

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

◆ __str__()

searx.query.RawTextQuery.__str__ ( self)

Definition at line 332 of file query.py.

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

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 280 of file query.py.

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

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 316 of file query.py.

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

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 311 of file query.py.

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

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 326 of file query.py.

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

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 323 of file query.py.

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

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

searx.query.RawTextQuery.autocomplete_list

Definition at line 272 of file query.py.

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

◆ autocomplete_location

searx.query.RawTextQuery.autocomplete_location

◆ disabled_engines

searx.query.RawTextQuery.disabled_engines

Definition at line 265 of file query.py.

◆ enginerefs

searx.query.RawTextQuery.enginerefs

Definition at line 267 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 253 of file query.py.

◆ query

◆ query_parts

searx.query.RawTextQuery.query_parts

◆ redirect_to_first_result

◆ specific

searx.query.RawTextQuery.specific

Definition at line 271 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: