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

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

Protected Member Functions

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

Additional Inherited Members

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

Detailed Description

Definition at line 73 of file query.py.

Member Function Documentation

◆ __call__()

searx.query.LanguageParser.__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 78 of file query.py.

78 def __call__(self, raw_value):
79 value = raw_value[1:].lower().replace('_', '-')
80 found = self._parse(value) if len(value) > 0 else False
81 if self.enable_autocomplete and not found:
82 self._autocomplete(value)
83 return found
84

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

+ Here is the call graph for this function:

◆ _autocomplete()

searx.query.LanguageParser._autocomplete ( self,
value )
protected

Definition at line 119 of file query.py.

119 def _autocomplete(self, value):
120 if not value:
121 # show some example queries
122 if len(settings['search']['languages']) < 10:
123 for lang in settings['search']['languages']:
124 self.raw_text_query.autocomplete_list.append(':' + lang)
125 else:
126 for lang in [":en", ":en_us", ":english", ":united_kingdom"]:
127 self.raw_text_query.autocomplete_list.append(lang)
128 return
129
130 for lc in sxng_locales:
131 if lc[0] not in settings['search']['languages']:
132 continue
133 lang_id, lang_name, country, english_name, _flag = map(str.lower, lc)
134
135 # check if query starts with language-id
136 if lang_id.startswith(value):
137 if len(value) <= 2:
138 self._add_autocomplete(':' + lang_id.split('-')[0])
139 else:
140 self._add_autocomplete(':' + lang_id)
141
142 # check if query starts with language name
143 if lang_name.startswith(value) or english_name.startswith(value):
144 self._add_autocomplete(':' + lang_name)
145
146 # check if query starts with country
147 # here "new_zealand" is "new-zealand" (see __call__)
148 if country.startswith(value.replace('-', ' ')):
149 self._add_autocomplete(':' + country.replace(' ', '_'))
150
151

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.LanguageParser._parse ( self,
value )
protected

Definition at line 85 of file query.py.

85 def _parse(self, value):
86 found = False
87 # check if any language-code is equal with
88 # declared language-codes
89 for lc in sxng_locales:
90 lang_id, lang_name, country, english_name, _flag = map(str.lower, lc)
91
92 # if correct language-code is found
93 # set it as new search-language
94
95 if (
96 value == lang_id or value == lang_name or value == english_name or value.replace('-', ' ') == country
97 ) and value not in self.raw_text_query.languages:
98 found = True
99 lang_parts = lang_id.split('-')
100 if len(lang_parts) == 2:
101 self.raw_text_query.languages.append(lang_parts[0] + '-' + lang_parts[1].upper())
102 else:
103 self.raw_text_query.languages.append(lang_id)
104 # to ensure best match (first match is not necessarily the best one)
105 if value == lang_id:
106 break
107
108 # user may set a valid, yet not selectable language
109 if VALID_LANGUAGE_CODE.match(value) or value == 'auto':
110 lang_parts = value.split('-')
111 if len(lang_parts) > 1:
112 value = lang_parts[0].lower() + '-' + lang_parts[1].upper()
113 if value not in self.raw_text_query.languages:
114 self.raw_text_query.languages.append(value)
115 found = True
116
117 return found
118

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.LanguageParser.check ( raw_value)
static
Check if raw_value can be parsed

Reimplemented from searx.query.QueryPartParser.

Definition at line 75 of file query.py.

75 def check(raw_value):
76 return raw_value[0] == ':'
77

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