summaryrefslogtreecommitdiff
path: root/searx/query.py
diff options
context:
space:
mode:
authorAdam Tauber <asciimoo@gmail.com>2017-12-06 14:34:26 +0100
committerGitHub <noreply@github.com>2017-12-06 14:34:26 +0100
commit49b845051f027cf9d29a20821968103a0f55c9d9 (patch)
tree249693fb31423283ee21c5ded4bed844d7250f2e /searx/query.py
parentdf0b8ee5270a37642ccf5f42e95b0656aefc7fda (diff)
parent4d1770398a6af8902e75c0bd885781584d39e796 (diff)
downloadsearxng-49b845051f027cf9d29a20821968103a0f55c9d9.tar.gz
searxng-49b845051f027cf9d29a20821968103a0f55c9d9.zip
Merge pull request #973 from MarcAbonce/languages
Remove 'all' option from search languages
Diffstat (limited to 'searx/query.py')
-rw-r--r--searx/query.py34
1 files changed, 19 insertions, 15 deletions
diff --git a/searx/query.py b/searx/query.py
index e4483f188..6e5f2e883 100644
--- a/searx/query.py
+++ b/searx/query.py
@@ -73,11 +73,6 @@ class RawTextQuery(object):
if query_part[0] == ':':
lang = query_part[1:].lower().replace('_', '-')
- # user may set a valid, yet not selectable language
- if VALID_LANGUAGE_CODE.match(lang):
- self.languages.append(lang)
- parse_next = True
-
# check if any language-code is equal with
# declared language-codes
for lc in language_codes:
@@ -85,16 +80,25 @@ class RawTextQuery(object):
# if correct language-code is found
# set it as new search-language
- if lang == lang_id\
- or lang_id.startswith(lang)\
- or lang == lang_name\
- or lang == english_name\
- or lang.replace('-', ' ') == country:
- parse_next = True
- self.languages.append(lang_id)
- # to ensure best match (first match is not necessarily the best one)
- if lang == lang_id:
- break
+ if (lang == lang_id
+ or lang == lang_name
+ or lang == english_name
+ or lang.replace('-', ' ') == country)\
+ and lang not in self.languages:
+ parse_next = True
+ lang_parts = lang_id.split('-')
+ if len(lang_parts) == 2:
+ self.languages.append(lang_parts[0] + '-' + lang_parts[1].upper())
+ else:
+ self.languages.append(lang_id)
+ # to ensure best match (first match is not necessarily the best one)
+ if lang == lang_id:
+ break
+
+ # user may set a valid, yet not selectable language
+ if not self.languages and VALID_LANGUAGE_CODE.match(lang):
+ self.languages.append(lang)
+ parse_next = True
# this force a engine or category
if query_part[0] == '!' or query_part[0] == '?':