From fd65c1292179fb082e965a1ee6a88b9298a54fc1 Mon Sep 17 00:00:00 2001 From: marc Date: Wed, 1 Mar 2017 17:11:51 -0600 Subject: make search language handling less strict languages.py can change, so users may query on a language that is not on the list anymore, even if it is still recognized by a few engines. also made no and nb the same because they seem to return the same, though most engines will only support one or the other. --- searx/query.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'searx/query.py') diff --git a/searx/query.py b/searx/query.py index 66e38711c..b8b1c0d2f 100644 --- a/searx/query.py +++ b/searx/query.py @@ -24,7 +24,7 @@ from searx.engines import ( import string import re -VALID_LANGUAGE_CODE = re.compile(r'^[a-z]{2,3}(\-[A-Z]{2})?$') +VALID_LANGUAGE_CODE = re.compile(r'^[a-z]{2,3}(-[a-zA-Z]{2})?$') class RawTextQuery(object): @@ -68,7 +68,7 @@ class RawTextQuery(object): # this force a language if query_part[0] == ':': - lang = query_part[1:].lower() + lang = query_part[1:].lower().replace('_', '-') # user may set a valid, yet not selectable language if VALID_LANGUAGE_CODE.match(lang): @@ -86,7 +86,7 @@ class RawTextQuery(object): or lang_id.startswith(lang)\ or lang == lang_name\ or lang == english_name\ - or lang.replace('_', ' ') == country: + or lang.replace('-', ' ') == country: parse_next = True self.languages.append(lang_id) # to ensure best match (first match is not necessarily the best one) -- cgit v1.2.3