Przeglądaj źródła

Merge pull request #973 from MarcAbonce/languages

Remove 'all' option from search languages
Adam Tauber 7 lat temu
rodzic
commit
49b845051f
Brak konta powiązanego z e-mailem autora
56 zmienionych plików z 166 dodań i 249 usunięć
  1. 3
    3
      searx/engines/archlinux.py
  2. 1
    4
      searx/engines/bing.py
  3. 1
    4
      searx/engines/bing_news.py
  4. 1
    4
      searx/engines/dailymotion.py
  5. 3
    9
      searx/engines/duckduckgo.py
  6. 2
    6
      searx/engines/duckduckgo_images.py
  7. 1
    4
      searx/engines/faroo.py
  8. 3
    6
      searx/engines/gigablast.py
  9. 2
    1
      searx/engines/google.py
  10. 2
    3
      searx/engines/google_news.py
  11. 1
    4
      searx/engines/mediawiki.py
  12. 3
    4
      searx/engines/photon.py
  13. 11
    12
      searx/engines/qwant.py
  14. 2
    3
      searx/engines/startpage.py
  15. 1
    1
      searx/engines/subtitleseeker.py
  16. 1
    4
      searx/engines/swisscows.py
  17. 1
    6
      searx/engines/twitter.py
  18. 0
    4
      searx/engines/wikidata.py
  19. 1
    1
      searx/engines/wikipedia.py
  20. 1
    3
      searx/engines/yacy.py
  21. 1
    3
      searx/engines/yahoo.py
  22. 1
    4
      searx/engines/yahoo_news.py
  23. 1
    3
      searx/engines/youtube_api.py
  24. 0
    1
      searx/preferences.py
  25. 19
    15
      searx/query.py
  26. 5
    1
      searx/search.py
  27. 1
    1
      searx/settings.yml
  28. 1
    1
      searx/settings_robot.yml
  29. 0
    1
      searx/templates/courgette/preferences.html
  30. 0
    1
      searx/templates/legacy/preferences.html
  31. 5
    6
      searx/templates/oscar/languages.html
  32. 2
    2
      searx/templates/oscar/preferences.html
  33. 0
    1
      searx/templates/pix-art/preferences.html
  34. 2
    2
      searx/webapp.py
  35. 1
    1
      tests/unit/engines/test_archlinux.py
  36. 1
    5
      tests/unit/engines/test_bing.py
  37. 0
    4
      tests/unit/engines/test_bing_news.py
  38. 0
    4
      tests/unit/engines/test_dailymotion.py
  39. 1
    1
      tests/unit/engines/test_duckduckgo_images.py
  40. 2
    6
      tests/unit/engines/test_faroo.py
  41. 1
    6
      tests/unit/engines/test_gigablast.py
  42. 1
    1
      tests/unit/engines/test_google.py
  43. 1
    6
      tests/unit/engines/test_google_news.py
  44. 0
    4
      tests/unit/engines/test_mediawiki.py
  45. 2
    1
      tests/unit/engines/test_qwant.py
  46. 0
    4
      tests/unit/engines/test_startpage.py
  47. 0
    36
      tests/unit/engines/test_subtitleseeker.py
  48. 0
    5
      tests/unit/engines/test_swisscows.py
  49. 0
    6
      tests/unit/engines/test_twitter.py
  50. 3
    3
      tests/unit/engines/test_wikidata.py
  51. 0
    4
      tests/unit/engines/test_wikipedia.py
  52. 0
    5
      tests/unit/engines/test_yacy.py
  53. 0
    7
      tests/unit/engines/test_yahoo.py
  54. 0
    7
      tests/unit/engines/test_yahoo_news.py
  55. 10
    5
      tests/unit/test_preferences.py
  56. 64
    0
      tests/unit/test_query.py

+ 3
- 3
searx/engines/archlinux.py Wyświetl plik

@@ -26,7 +26,7 @@ xpath_results = '//ul[@class="mw-search-results"]/li'
26 26
 xpath_link = './/div[@class="mw-search-result-heading"]/a'
27 27
 
28 28
 
29
-# cut 'en' from 'en_US', 'de' from 'de_CH', and so on
29
+# cut 'en' from 'en-US', 'de' from 'de-CH', and so on
30 30
 def locale_to_lang_code(locale):
31 31
     if locale.find('-') >= 0:
32 32
         locale = locale.split('-')[0]
@@ -36,7 +36,7 @@ def locale_to_lang_code(locale):
36 36
 # wikis for some languages were moved off from the main site, we need to make
37 37
 # requests to correct URLs to be able to get results in those languages
38 38
 lang_urls = {
39
-    'all': {
39
+    'en': {
40 40
         'base': 'https://wiki.archlinux.org',
41 41
         'search': '/index.php?title=Special:Search&offset={offset}&{query}'
42 42
     },
@@ -67,7 +67,7 @@ lang_urls = {
67 67
 def get_lang_urls(language):
68 68
     if language in lang_urls:
69 69
         return lang_urls[language]
70
-    return lang_urls['all']
70
+    return lang_urls['en']
71 71
 
72 72
 
73 73
 # Language names to build search requests for

+ 1
- 4
searx/engines/bing.py Wyświetl plik

@@ -32,10 +32,7 @@ search_string = 'search?{query}&first={offset}'
32 32
 def request(query, params):
33 33
     offset = (params['pageno'] - 1) * 10 + 1
34 34
 
35
-    if params['language'] != 'all':
36
-        lang = params['language'].split('-')[0].upper()
37
-    else:
38
-        lang = 'EN'
35
+    lang = params['language'].split('-')[0].upper()
39 36
 
40 37
     query = u'language:{} {}'.format(lang, query.decode('utf-8')).encode('utf-8')
41 38
 

+ 1
- 4
searx/engines/bing_news.py Wyświetl plik

@@ -71,10 +71,7 @@ def request(query, params):
71 71
 
72 72
     offset = (params['pageno'] - 1) * 10 + 1
73 73
 
74
-    if params['language'] == 'all':
75
-        language = 'en-US'
76
-    else:
77
-        language = params['language']
74
+    language = params['language']
78 75
 
79 76
     params['url'] = _get_url(query, language, offset, params['time_range'])
80 77
 

+ 1
- 4
searx/engines/dailymotion.py Wyświetl plik

@@ -32,10 +32,7 @@ supported_languages_url = 'https://api.dailymotion.com/languages'
32 32
 
33 33
 # do search-request
34 34
 def request(query, params):
35
-    if params['language'] == 'all':
36
-        locale = 'en-US'
37
-    else:
38
-        locale = params['language']
35
+    locale = params['language']
39 36
 
40 37
     params['url'] = search_url.format(
41 38
         query=urlencode({'search': query, 'localization': locale}),

+ 3
- 9
searx/engines/duckduckgo.py Wyświetl plik

@@ -44,9 +44,7 @@ content_xpath = './/a[@class="result__snippet"]'
44 44
 # match query's language to a region code that duckduckgo will accept
45 45
 def get_region_code(lang, lang_list=None):
46 46
     # custom fixes for languages
47
-    if lang == 'all':
48
-        region_code = None
49
-    elif lang[:2] == 'ja':
47
+    if lang[:2] == 'ja':
50 48
         region_code = 'jp-jp'
51 49
     elif lang[:2] == 'sl':
52 50
         region_code = 'sl-sl'
@@ -82,12 +80,8 @@ def request(query, params):
82 80
     offset = (params['pageno'] - 1) * 30
83 81
 
84 82
     region_code = get_region_code(params['language'])
85
-    if region_code:
86
-        params['url'] = url.format(
87
-            query=urlencode({'q': query, 'kl': region_code}), offset=offset, dc_param=offset)
88
-    else:
89
-        params['url'] = url.format(
90
-            query=urlencode({'q': query}), offset=offset, dc_param=offset)
83
+    params['url'] = url.format(
84
+        query=urlencode({'q': query, 'kl': region_code}), offset=offset, dc_param=offset)
91 85
 
92 86
     if params['time_range'] in time_range_dict:
93 87
         params['url'] += time_range_url.format(range=time_range_dict[params['time_range']])

+ 2
- 6
searx/engines/duckduckgo_images.py Wyświetl plik

@@ -53,12 +53,8 @@ def request(query, params):
53 53
     safesearch = params['safesearch'] - 1
54 54
 
55 55
     region_code = get_region_code(params['language'], lang_list=supported_languages)
56
-    if region_code:
57
-        params['url'] = images_url.format(
58
-            query=urlencode({'q': query, 'l': region_code}), offset=offset, safesearch=safesearch, vqd=vqd)
59
-    else:
60
-        params['url'] = images_url.format(
61
-            query=urlencode({'q': query}), offset=offset, safesearch=safesearch, vqd=vqd)
56
+    params['url'] = images_url.format(
57
+        query=urlencode({'q': query, 'l': region_code}), offset=offset, safesearch=safesearch, vqd=vqd)
62 58
 
63 59
     return params
64 60
 

+ 1
- 4
searx/engines/faroo.py Wyświetl plik

@@ -40,10 +40,7 @@ def request(query, params):
40 40
     offset = (params['pageno'] - 1) * number_of_results + 1
41 41
     categorie = search_category.get(params['category'], 'web')
42 42
 
43
-    if params['language'] == 'all':
44
-        language = 'en'
45
-    else:
46
-        language = params['language'].split('_')[0]
43
+    language = params['language'].split('-')[0]
47 44
 
48 45
     # if language is not supported, put it in english
49 46
     if language != 'en' and\

+ 3
- 6
searx/engines/gigablast.py Wyświetl plik

@@ -49,12 +49,9 @@ supported_languages_url = 'https://gigablast.com/search?&rxikd=1'
49 49
 def request(query, params):
50 50
     offset = (params['pageno'] - 1) * number_of_results
51 51
 
52
-    if params['language'] == 'all':
53
-        language = 'xx'
54
-    else:
55
-        language = params['language'].replace('-', '_').lower()
56
-        if language.split('-')[0] != 'zh':
57
-            language = language.split('-')[0]
52
+    language = params['language'].replace('-', '_').lower()
53
+    if language.split('-')[0] != 'zh':
54
+        language = language.split('-')[0]
58 55
 
59 56
     if params['safesearch'] >= 1:
60 57
         safesearch = 1

+ 2
- 1
searx/engines/google.py Wyświetl plik

@@ -165,7 +165,8 @@ def extract_text_from_dom(result, xpath):
165 165
 def request(query, params):
166 166
     offset = (params['pageno'] - 1) * 10
167 167
 
168
-    if params['language'] == 'all':
168
+    # temporary fix until a way of supporting en-US is found
169
+    if params['language'] == 'en-US':
169 170
         params['language'] = 'en-GB'
170 171
 
171 172
     if params['language'][:2] == 'jv':

+ 2
- 3
searx/engines/google_news.py Wyświetl plik

@@ -50,9 +50,8 @@ def request(query, params):
50 50
     params['url'] = search_url.format(query=urlencode({'q': query}),
51 51
                                       search_options=urlencode(search_options))
52 52
 
53
-    if params['language'] != 'all':
54
-        language_array = params['language'].lower().split('-')
55
-        params['url'] += '&lr=lang_' + language_array[0]
53
+    language_array = params['language'].lower().split('-')
54
+    params['url'] += '&lr=lang_' + language_array[0]
56 55
 
57 56
     return params
58 57
 

+ 1
- 4
searx/engines/mediawiki.py Wyświetl plik

@@ -45,10 +45,7 @@ def request(query, params):
45 45
 
46 46
     format_strings = list(Formatter().parse(base_url))
47 47
 
48
-    if params['language'] == 'all':
49
-        language = 'en'
50
-    else:
51
-        language = params['language'].split('-')[0]
48
+    language = params['language'].split('-')[0]
52 49
 
53 50
     # format_string [('https://', 'language', '', None), ('.wikipedia.org/', None, None, None)]
54 51
     if any(x[1] == 'language' for x in format_strings):

+ 3
- 4
searx/engines/photon.py Wyświetl plik

@@ -35,10 +35,9 @@ def request(query, params):
35 35
         search_string.format(query=urlencode({'q': query}),
36 36
                              limit=number_of_results)
37 37
 
38
-    if params['language'] != 'all':
39
-        language = params['language'].split('_')[0]
40
-        if language in supported_languages:
41
-            params['url'] = params['url'] + "&lang=" + language
38
+    language = params['language'].split('-')[0]
39
+    if language in supported_languages:
40
+        params['url'] = params['url'] + "&lang=" + language
42 41
 
43 42
     # using searx User-Agent
44 43
     params['headers']['User-Agent'] = searx_useragent()

+ 11
- 12
searx/engines/qwant.py Wyświetl plik

@@ -44,18 +44,17 @@ def request(query, params):
44 44
                                    query=urlencode({'q': query}),
45 45
                                    offset=offset)
46 46
 
47
-    # add language tag if specified
48
-    if params['language'] != 'all':
49
-        if params['language'] == 'no' or params['language'].startswith('no-'):
50
-            params['language'] = params['language'].replace('no', 'nb', 1)
51
-        if params['language'].find('-') < 0:
52
-            # tries to get a country code from language
53
-            for lang in supported_languages:
54
-                lc = lang.split('-')
55
-                if params['language'] == lc[0]:
56
-                    params['language'] = lang
57
-                    break
58
-        params['url'] += '&locale=' + params['language'].replace('-', '_').lower()
47
+    # add language tag
48
+    if params['language'] == 'no' or params['language'].startswith('no-'):
49
+        params['language'] = params['language'].replace('no', 'nb', 1)
50
+    if params['language'].find('-') < 0:
51
+        # tries to get a country code from language
52
+        for lang in supported_languages:
53
+            lc = lang.split('-')
54
+            if params['language'] == lc[0]:
55
+                params['language'] = lang
56
+                break
57
+    params['url'] += '&locale=' + params['language'].replace('-', '_').lower()
59 58
 
60 59
     return params
61 60
 

+ 2
- 3
searx/engines/startpage.py Wyświetl plik

@@ -45,9 +45,8 @@ def request(query, params):
45 45
     params['data'] = {'query': query,
46 46
                       'startat': offset}
47 47
 
48
-    # set language if specified
49
-    if params['language'] != 'all':
50
-        params['data']['with_language'] = ('lang_' + params['language'].split('-')[0])
48
+    # set language
49
+    params['data']['with_language'] = ('lang_' + params['language'].split('-')[0])
51 50
 
52 51
     return params
53 52
 

+ 1
- 1
searx/engines/subtitleseeker.py Wyświetl plik

@@ -48,7 +48,7 @@ def response(resp):
48 48
         search_lang = 'Farsi'
49 49
     elif resp.search_params['language'] == 'pt-BR':
50 50
         search_lang = 'Brazilian'
51
-    elif resp.search_params['language'] != 'all':
51
+    else:
52 52
         search_lang = [lc[3]
53 53
                        for lc in language_codes
54 54
                        if lc[0].split('-')[0] == resp.search_params['language'].split('-')[0]]

+ 1
- 4
searx/engines/swisscows.py Wyświetl plik

@@ -35,10 +35,7 @@ regex_img_url_remove_start = re.compile(b'^https?://i\.swisscows\.ch/\?link=')
35 35
 
36 36
 # do search-request
37 37
 def request(query, params):
38
-    if params['language'] == 'all':
39
-        ui_language = 'browser'
40
-        region = 'browser'
41
-    elif params['language'].split('-')[0] == 'no':
38
+    if params['language'].split('-')[0] == 'no':
42 39
         region = 'nb-NO'
43 40
     else:
44 41
         region = params['language']

+ 1
- 6
searx/engines/twitter.py Wyświetl plik

@@ -37,12 +37,7 @@ timestamp_xpath = './/span[contains(@class,"_timestamp")]'
37 37
 # do search-request
38 38
 def request(query, params):
39 39
     params['url'] = search_url + urlencode({'q': query})
40
-
41
-    # set language if specified
42
-    if params['language'] != 'all':
43
-        params['cookies']['lang'] = params['language'].split('-')[0]
44
-    else:
45
-        params['cookies']['lang'] = 'en'
40
+    params['cookies']['lang'] = params['language'].split('-')[0]
46 41
 
47 42
     return params
48 43
 

+ 0
- 4
searx/engines/wikidata.py Wyświetl plik

@@ -57,8 +57,6 @@ calendar_name_xpath = './/sup[contains(@class,"wb-calendar-name")]'
57 57
 
58 58
 def request(query, params):
59 59
     language = params['language'].split('-')[0]
60
-    if language == 'all':
61
-        language = 'en'
62 60
 
63 61
     params['url'] = url_search.format(
64 62
         query=urlencode({'label': query, 'language': language}))
@@ -71,8 +69,6 @@ def response(resp):
71 69
     wikidata_ids = html.xpath(wikidata_ids_xpath)
72 70
 
73 71
     language = resp.search_params['language'].split('-')[0]
74
-    if language == 'all':
75
-        language = 'en'
76 72
 
77 73
     # TODO: make requests asynchronous to avoid timeout when result_count > 1
78 74
     for wikidata_id in wikidata_ids[:result_count]:

+ 1
- 1
searx/engines/wikipedia.py Wyświetl plik

@@ -31,7 +31,7 @@ supported_languages_url = 'https://meta.wikimedia.org/wiki/List_of_Wikipedias'
31 31
 # set language in base_url
32 32
 def url_lang(lang):
33 33
     lang = lang.split('-')[0]
34
-    if lang == 'all' or lang not in supported_languages:
34
+    if lang not in supported_languages:
35 35
         language = 'en'
36 36
     else:
37 37
         language = lang

+ 1
- 3
searx/engines/yacy.py Wyświetl plik

@@ -51,9 +51,7 @@ def request(query, params):
51 51
                           limit=number_of_results,
52 52
                           search_type=search_type)
53 53
 
54
-    # add language tag if specified
55
-    if params['language'] != 'all':
56
-        params['url'] += '&lr=lang_' + params['language'].split('-')[0]
54
+    params['url'] += '&lr=lang_' + params['language'].split('-')[0]
57 55
 
58 56
     return params
59 57
 

+ 1
- 3
searx/engines/yahoo.py Wyświetl plik

@@ -71,9 +71,7 @@ def _get_url(query, offset, language, time_range):
71 71
 
72 72
 
73 73
 def _get_language(params):
74
-    if params['language'] == 'all':
75
-        return 'en'
76
-    elif params['language'][:2] == 'zh':
74
+    if params['language'][:2] == 'zh':
77 75
         if params['language'] == 'zh' or params['language'] == 'zh-CH':
78 76
             return 'szh'
79 77
         else:

+ 1
- 4
searx/engines/yahoo_news.py Wyświetl plik

@@ -38,10 +38,7 @@ suggestion_xpath = '//div[contains(@class,"VerALSOTRY")]//a'
38 38
 def request(query, params):
39 39
     offset = (params['pageno'] - 1) * 10 + 1
40 40
 
41
-    if params['language'] == 'all':
42
-        language = 'en'
43
-    else:
44
-        language = params['language'].split('_')[0]
41
+    language = params['language'].split('-')[0]
45 42
 
46 43
     params['url'] = search_url.format(offset=offset,
47 44
                                       query=urlencode({'p': query}),

+ 1
- 3
searx/engines/youtube_api.py Wyświetl plik

@@ -34,9 +34,7 @@ def request(query, params):
34 34
     params['url'] = search_url.format(query=urlencode({'q': query}),
35 35
                                       api_key=api_key)
36 36
 
37
-    # add language tag if specified
38
-    if params['language'] != 'all':
39
-        params['url'] += '&relevanceLanguage=' + params['language'].split('-')[0]
37
+    params['url'] += '&relevanceLanguage=' + params['language'].split('-')[0]
40 38
 
41 39
     return params
42 40
 

+ 0
- 1
searx/preferences.py Wyświetl plik

@@ -12,7 +12,6 @@ if version[0] == '3':
12 12
 
13 13
 COOKIE_MAX_AGE = 60 * 60 * 24 * 365 * 5  # 5 years
14 14
 LANGUAGE_CODES = [l[0] for l in languages]
15
-LANGUAGE_CODES.append('all')
16 15
 DISABLED = 0
17 16
 ENABLED = 1
18 17
 DOI_RESOLVERS = list(settings['doi_resolvers'])

+ 19
- 15
searx/query.py Wyświetl plik

@@ -73,11 +73,6 @@ class RawTextQuery(object):
73 73
             if query_part[0] == ':':
74 74
                 lang = query_part[1:].lower().replace('_', '-')
75 75
 
76
-                # user may set a valid, yet not selectable language
77
-                if VALID_LANGUAGE_CODE.match(lang):
78
-                    self.languages.append(lang)
79
-                    parse_next = True
80
-
81 76
                 # check if any language-code is equal with
82 77
                 # declared language-codes
83 78
                 for lc in language_codes:
@@ -85,16 +80,25 @@ class RawTextQuery(object):
85 80
 
86 81
                     # if correct language-code is found
87 82
                     # set it as new search-language
88
-                    if lang == lang_id\
89
-                       or lang_id.startswith(lang)\
90
-                       or lang == lang_name\
91
-                       or lang == english_name\
92
-                       or lang.replace('-', ' ') == country:
93
-                        parse_next = True
94
-                        self.languages.append(lang_id)
95
-                        # to ensure best match (first match is not necessarily the best one)
96
-                        if lang == lang_id:
97
-                            break
83
+                    if (lang == lang_id
84
+                        or lang == lang_name
85
+                        or lang == english_name
86
+                        or lang.replace('-', ' ') == country)\
87
+                       and lang not in self.languages:
88
+                            parse_next = True
89
+                            lang_parts = lang_id.split('-')
90
+                            if len(lang_parts) == 2:
91
+                                self.languages.append(lang_parts[0] + '-' + lang_parts[1].upper())
92
+                            else:
93
+                                self.languages.append(lang_id)
94
+                            # to ensure best match (first match is not necessarily the best one)
95
+                            if lang == lang_id:
96
+                                break
97
+
98
+                # user may set a valid, yet not selectable language
99
+                if not self.languages and VALID_LANGUAGE_CODE.match(lang):
100
+                    self.languages.append(lang)
101
+                    parse_next = True
98 102
 
99 103
             # this force a engine or category
100 104
             if query_part[0] == '!' or query_part[0] == '?':

+ 5
- 1
searx/search.py Wyświetl plik

@@ -24,7 +24,7 @@ from flask_babel import gettext
24 24
 import requests.exceptions
25 25
 import searx.poolrequests as requests_lib
26 26
 from searx.engines import (
27
-    categories, engines
27
+    categories, engines, settings
28 28
 )
29 29
 from searx.answerers import ask
30 30
 from searx.utils import gen_useragent
@@ -220,6 +220,10 @@ def get_search_query_from_webapp(preferences, form):
220 220
     else:
221 221
         query_lang = preferences.get_value('language')
222 222
 
223
+    # provides backwards compatibility for requests using old language default
224
+    if query_lang == 'all':
225
+        query_lang = settings['search']['language']
226
+
223 227
     # check language
224 228
     if not VALID_LANGUAGE_CODE.match(query_lang):
225 229
         raise SearxParameterException('language', query_lang)

+ 1
- 1
searx/settings.yml Wyświetl plik

@@ -5,7 +5,7 @@ general:
5 5
 search:
6 6
     safe_search : 0 # Filter results. 0: None, 1: Moderate, 2: Strict
7 7
     autocomplete : "" # Existing autocomplete backends: "dbpedia", "duckduckgo", "google", "startpage", "wikipedia" - leave blank to turn it off by default
8
-    language : "all"
8
+    language : "en-US"
9 9
 
10 10
 server:
11 11
     port : 8888

+ 1
- 1
searx/settings_robot.yml Wyświetl plik

@@ -5,7 +5,7 @@ general:
5 5
 search:
6 6
     safe_search : 0
7 7
     autocomplete : ""
8
-    language: "all"
8
+    language: "en-US"
9 9
 
10 10
 server:
11 11
     port : 11111

+ 0
- 1
searx/templates/courgette/preferences.html Wyświetl plik

@@ -13,7 +13,6 @@
13 13
         <legend>{{ _('Search language') }}</legend>
14 14
         <p>
15 15
             <select name='language'>
16
-                <option value="all" {% if current_language == 'all' %}selected="selected"{% endif %}>{{ _('Default language') }}</option>
17 16
                 {% for lang_id,lang_name,country_name,english_name in language_codes | sort(attribute=1) %}
18 17
                 <option value="{{ lang_id }}" {% if lang_id == current_language %}selected="selected"{% endif %}>{{ lang_name }} {% if country_name %}({{ country_name }}) {% endif %}- {{ lang_id }}</option>
19 18
                 {% endfor %}

+ 0
- 1
searx/templates/legacy/preferences.html Wyświetl plik

@@ -14,7 +14,6 @@
14 14
         <legend>{{ _('Search language') }}</legend>
15 15
         <p>
16 16
         <select name='language'>
17
-            <option value="all" {% if current_language == 'all' %}selected="selected"{% endif %}>{{ _('Default language') }}</option>
18 17
             {% for lang_id,lang_name,country_name,english_name in language_codes | sort(attribute=1) %}
19 18
             <option value="{{ lang_id }}" {% if lang_id == current_language %}selected="selected"{% endif %}>{{ lang_name }} {% if country_name %}({{ country_name }}) {% endif %}- {{ lang_id }}</option>
20 19
             {% endfor %}

+ 5
- 6
searx/templates/oscar/languages.html Wyświetl plik

@@ -3,10 +3,9 @@
3 3
 {% else %}
4 4
 <select class="time_range custom-select form-control" id='language' name='language'>
5 5
 {% endif %}
6
-	<option value="all" {% if current_language == 'all' %}selected="selected"{% endif %}>{{ _('Default language') }}</option>
7
-		{% for lang_id,lang_name,country_name,english_name in language_codes | sort(attribute=1) %}
8
-		<option value="{{ lang_id }}" {% if lang_id == current_language %}selected="selected"{% endif %}>
9
-			{{ lang_name }} {% if country_name %}({{ country_name }}) {% endif %}- {{ lang_id }}
10
-		</option>
11
-		{% endfor %}
6
+	{% for lang_id,lang_name,country_name,english_name in language_codes | sort(attribute=1) %}
7
+	<option value="{{ lang_id }}" {% if lang_id == current_language %}selected="selected"{% endif %}>
8
+		{{ lang_name }} {% if country_name %}({{ country_name }}) {% endif %}- {{ lang_id }}
9
+	</option>
10
+	{% endfor %}
12 11
 </select>

+ 2
- 2
searx/templates/oscar/preferences.html Wyświetl plik

@@ -187,7 +187,7 @@
187 187
                                     </td>
188 188
                                     <th>{{ search_engine.name }}</th>
189 189
 				    <td class="name">{{ shortcuts[search_engine.name] }}</td>
190
-					<td>{{ support_toggle(current_language == 'all' or current_language in search_engine.supported_languages or current_language.split('-')[0] in search_engine.supported_languages) }}</td>
190
+					<td>{{ support_toggle(current_language in search_engine.supported_languages or current_language.split('-')[0] in search_engine.supported_languages) }}</td>
191 191
 					<td>{{ support_toggle(search_engine.safesearch==True) }}</td>
192 192
 					<td>{{ support_toggle(search_engine.time_range_support==True) }}</td>
193 193
 					<td class="{{ 'danger' if stats[search_engine.name]['warn_time'] else '' }}">{{ 'N/A' if stats[search_engine.name].time==None else stats[search_engine.name].time }}</td>
@@ -197,7 +197,7 @@
197 197
 					<td class="{{ 'danger' if stats[search_engine.name]['warn_time'] else '' }}">{{ 'N/A' if stats[search_engine.name].time==None else stats[search_engine.name].time }}</td>
198 198
 					<td>{{ support_toggle(search_engine.time_range_support==True) }}</td>
199 199
 					<td>{{ support_toggle(search_engine.safesearch==True) }}</td>
200
-					<td>{{ support_toggle(current_language == 'all' or current_language in search_engine.supported_languages or current_language.split('-')[0] in search_engine.supported_languages) }}</td>
200
+					<td>{{ support_toggle(current_language in search_engine.supported_languages or current_language.split('-')[0] in search_engine.supported_languages) }}</td>
201 201
 					<td>{{ shortcuts[search_engine.name] }}</td>
202 202
                                     <th>{{ search_engine.name }}</th>
203 203
                                     <td class="onoff-checkbox">

+ 0
- 1
searx/templates/pix-art/preferences.html Wyświetl plik

@@ -9,7 +9,6 @@
9 9
         <legend>{{ _('Search language') }}</legend>
10 10
         <p>
11 11
         <select name='language'>
12
-            <option value="all" {% if current_language == 'all' %}selected="selected"{% endif %}>{{ _('Default language') }}</option>
13 12
             {% for lang_id,lang_name,country_name,english_name in language_codes | sort(attribute=1) %}
14 13
             <option value="{{ lang_id }}" {% if lang_id == current_language %}selected="selected"{% endif %}>{{ lang_name }} {% if country_name %}({{ country_name }}) {% endif %}- {{ lang_id }}</option>
15 14
             {% endfor %}

+ 2
- 2
searx/webapp.py Wyświetl plik

@@ -630,8 +630,8 @@ def autocompleter():
630 630
     if len(raw_results) <= 3 and completer:
631 631
         # get language from cookie
632 632
         language = request.preferences.get_value('language')
633
-        if not language or language == 'all':
634
-            language = 'en'
633
+        if not language:
634
+            language = settings['search']['language']
635 635
         else:
636 636
             language = language.split('-')[0]
637 637
         # run autocompletion

+ 1
- 1
tests/unit/engines/test_archlinux.py Wyświetl plik

@@ -4,7 +4,7 @@ from searx.engines import archlinux
4 4
 from searx.testing import SearxTestCase
5 5
 
6 6
 domains = {
7
-    'all': 'https://wiki.archlinux.org',
7
+    'en': 'https://wiki.archlinux.org',
8 8
     'de': 'https://wiki.archlinux.de',
9 9
     'fr': 'https://wiki.archlinux.fr',
10 10
     'ja': 'https://wiki.archlinuxjp.org',

+ 1
- 5
tests/unit/engines/test_bing.py Wyświetl plik

@@ -10,17 +10,13 @@ class TestBingEngine(SearxTestCase):
10 10
         query = u'test_query'
11 11
         dicto = defaultdict(dict)
12 12
         dicto['pageno'] = 0
13
-        dicto['language'] = 'fr_FR'
13
+        dicto['language'] = 'fr-FR'
14 14
         params = bing.request(query.encode('utf-8'), dicto)
15 15
         self.assertTrue('url' in params)
16 16
         self.assertTrue(query in params['url'])
17 17
         self.assertTrue('language%3AFR' in params['url'])
18 18
         self.assertTrue('bing.com' in params['url'])
19 19
 
20
-        dicto['language'] = 'all'
21
-        params = bing.request(query.encode('utf-8'), dicto)
22
-        self.assertTrue('language' in params['url'])
23
-
24 20
     def test_response(self):
25 21
         self.assertRaises(AttributeError, bing.response, None)
26 22
         self.assertRaises(AttributeError, bing.response, [])

+ 0
- 4
tests/unit/engines/test_bing_news.py Wyświetl plik

@@ -19,10 +19,6 @@ class TestBingNewsEngine(SearxTestCase):
19 19
         self.assertIn('bing.com', params['url'])
20 20
         self.assertIn('fr', params['url'])
21 21
 
22
-        dicto['language'] = 'all'
23
-        params = bing_news.request(query, dicto)
24
-        self.assertIn('en', params['url'])
25
-
26 22
     def test_no_url_in_request_year_time_range(self):
27 23
         dicto = defaultdict(dict)
28 24
         query = 'test_query'

+ 0
- 4
tests/unit/engines/test_dailymotion.py Wyświetl plik

@@ -18,10 +18,6 @@ class TestDailymotionEngine(SearxTestCase):
18 18
         self.assertTrue('dailymotion.com' in params['url'])
19 19
         self.assertTrue('fr' in params['url'])
20 20
 
21
-        dicto['language'] = 'all'
22
-        params = dailymotion.request(query, dicto)
23
-        self.assertTrue('en' in params['url'])
24
-
25 21
     def test_response(self):
26 22
         self.assertRaises(AttributeError, dailymotion.response, None)
27 23
         self.assertRaises(AttributeError, dailymotion.response, [])

+ 1
- 1
tests/unit/engines/test_duckduckgo_images.py Wyświetl plik

@@ -15,7 +15,7 @@ class TestDuckduckgoImagesEngine(SearxTestCase):
15 15
         dicto['is_test'] = True
16 16
         dicto['pageno'] = 1
17 17
         dicto['safesearch'] = 0
18
-        dicto['language'] = 'all'
18
+        dicto['language'] = 'en-US'
19 19
         params = duckduckgo_images.request(query, dicto)
20 20
         self.assertIn('url', params)
21 21
         self.assertIn(query, params['url'])

+ 2
- 6
tests/unit/engines/test_faroo.py Wyświetl plik

@@ -11,7 +11,7 @@ class TestFarooEngine(SearxTestCase):
11 11
         query = 'test_query'
12 12
         dicto = defaultdict(dict)
13 13
         dicto['pageno'] = 1
14
-        dicto['language'] = 'fr_FR'
14
+        dicto['language'] = 'fr-FR'
15 15
         dicto['category'] = 'general'
16 16
         params = faroo.request(query, dicto)
17 17
         self.assertIn('url', params)
@@ -20,11 +20,7 @@ class TestFarooEngine(SearxTestCase):
20 20
         self.assertIn('en', params['url'])
21 21
         self.assertIn('web', params['url'])
22 22
 
23
-        dicto['language'] = 'all'
24
-        params = faroo.request(query, dicto)
25
-        self.assertIn('en', params['url'])
26
-
27
-        dicto['language'] = 'de_DE'
23
+        dicto['language'] = 'de-DE'
28 24
         params = faroo.request(query, dicto)
29 25
         self.assertIn('de', params['url'])
30 26
 

+ 1
- 6
tests/unit/engines/test_gigablast.py Wyświetl plik

@@ -11,16 +11,11 @@ class TestGigablastEngine(SearxTestCase):
11 11
         dicto = defaultdict(dict)
12 12
         dicto['pageno'] = 0
13 13
         dicto['safesearch'] = 0
14
-        dicto['language'] = 'all'
14
+        dicto['language'] = 'en-US'
15 15
         params = gigablast.request(query, dicto)
16 16
         self.assertTrue('url' in params)
17 17
         self.assertTrue(query in params['url'])
18 18
         self.assertTrue('gigablast.com' in params['url'])
19
-        self.assertTrue('xx' in params['url'])
20
-
21
-        dicto['language'] = 'en-US'
22
-        params = gigablast.request(query, dicto)
23
-        self.assertTrue('en' in params['url'])
24 19
         self.assertFalse('en-US' in params['url'])
25 20
 
26 21
     def test_response(self):

+ 1
- 1
tests/unit/engines/test_google.py Wyświetl plik

@@ -26,7 +26,7 @@ class TestGoogleEngine(SearxTestCase):
26 26
         self.assertIn('google.fr', params['url'])
27 27
         self.assertIn('fr', params['headers']['Accept-Language'])
28 28
 
29
-        dicto['language'] = 'all'
29
+        dicto['language'] = 'en-US'
30 30
         params = google.request(query, dicto)
31 31
         self.assertIn('google.co', params['url'])
32 32
         self.assertIn('en', params['headers']['Accept-Language'])

+ 1
- 6
tests/unit/engines/test_google_news.py Wyświetl plik

@@ -12,18 +12,13 @@ class TestGoogleNewsEngine(SearxTestCase):
12 12
         query = 'test_query'
13 13
         dicto = defaultdict(dict)
14 14
         dicto['pageno'] = 1
15
-        dicto['language'] = 'fr_FR'
15
+        dicto['language'] = 'fr-FR'
16 16
         dicto['time_range'] = 'w'
17 17
         params = google_news.request(query, dicto)
18 18
         self.assertIn('url', params)
19 19
         self.assertIn(query, params['url'])
20 20
         self.assertIn('fr', params['url'])
21 21
 
22
-        dicto['language'] = 'all'
23
-        params = google_news.request(query, dicto)
24
-        self.assertIn('url', params)
25
-        self.assertNotIn('fr', params['url'])
26
-
27 22
     def test_response(self):
28 23
         self.assertRaises(AttributeError, google_news.response, None)
29 24
         self.assertRaises(AttributeError, google_news.response, [])

+ 0
- 4
tests/unit/engines/test_mediawiki.py Wyświetl plik

@@ -18,10 +18,6 @@ class TestMediawikiEngine(SearxTestCase):
18 18
         self.assertIn('wikipedia.org', params['url'])
19 19
         self.assertIn('fr', params['url'])
20 20
 
21
-        dicto['language'] = 'all'
22
-        params = mediawiki.request(query, dicto)
23
-        self.assertIn('en', params['url'])
24
-
25 21
         mediawiki.base_url = "http://test.url/"
26 22
         mediawiki.search_url = mediawiki.base_url +\
27 23
                                  'w/api.php?action=query'\

+ 2
- 1
tests/unit/engines/test_qwant.py Wyświetl plik

@@ -19,10 +19,11 @@ class TestQwantEngine(SearxTestCase):
19 19
         self.assertIn('qwant.com', params['url'])
20 20
         self.assertIn('fr_fr', params['url'])
21 21
 
22
-        dicto['language'] = 'all'
22
+        dicto['language'] = 'en-US'
23 23
         qwant.categories = ['news']
24 24
         params = qwant.request(query, dicto)
25 25
         self.assertFalse('fr' in params['url'])
26
+        self.assertIn('en_us', params['url'])
26 27
         self.assertIn('news', params['url'])
27 28
 
28 29
         qwant.supported_languages = ['en', 'fr-FR', 'fr-CA']

+ 0
- 4
tests/unit/engines/test_startpage.py Wyświetl plik

@@ -21,10 +21,6 @@ class TestStartpageEngine(SearxTestCase):
21 21
         self.assertIn('with_language', params['data'])
22 22
         self.assertIn('lang_fr', params['data']['with_language'])
23 23
 
24
-        dicto['language'] = 'all'
25
-        params = startpage.request(query, dicto)
26
-        self.assertNotIn('with_language', params['data'])
27
-
28 24
     def test_response(self):
29 25
         self.assertRaises(AttributeError, startpage.response, None)
30 26
         self.assertRaises(AttributeError, startpage.response, [])

+ 0
- 36
tests/unit/engines/test_subtitleseeker.py Wyświetl plik

@@ -99,42 +99,6 @@ class TestSubtitleseekerEngine(SearxTestCase):
99 99
             <div class="clear"></div>
100 100
         </div>
101 101
         """
102
-        dicto['language'] = 'all'
103
-        response = mock.Mock(text=html, search_params=dicto)
104
-        results = subtitleseeker.response(response)
105
-        self.assertEqual(type(results), list)
106
-        self.assertEqual(len(results), 1)
107
-        self.assertEqual(results[0]['title'], 'This is the Title')
108
-        self.assertEqual(results[0]['url'], 'http://this.is.the.url/')
109
-        self.assertIn('1998', results[0]['content'])
110
-        self.assertIn('1039 Subs', results[0]['content'])
111
-
112
-        html = """
113
-        <div class="boxRows">
114
-            <div class="boxRowsInner" style="width:600px;">
115
-                <img src="http://static.subtitleseeker.com/images/movie.gif"
116
-                    style="width:16px; height:16px;" class="icon">
117
-                <a href="http://this.is.the.url/"
118
-                    class="blue" title="Title subtitle" >
119
-                    This is the Title
120
-                </a>
121
-            </div>
122
-            <div class="boxRowsInner f12b red" style="width:70px;">
123
-                1998
124
-            </div>
125
-            <div class="boxRowsInner grey-web f12" style="width:120px;">
126
-                <img src="http://static.subtitleseeker.com/images/basket_put.png"
127
-                    style="width:16px; height:16px;" class="icon">
128
-                1039 Subs
129
-            </div>
130
-            <div class="boxRowsInner grey-web f10" style="width:130px;">
131
-                <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
132
-                    style="width:16px; height:16px;" class="icon">
133
-                1 hours ago
134
-            </div>
135
-            <div class="clear"></div>
136
-        </div>
137
-        """
138 102
         subtitleseeker.language = 'English'
139 103
         response = mock.Mock(text=html, search_params=dicto)
140 104
         results = subtitleseeker.response(response)

+ 0
- 5
tests/unit/engines/test_swisscows.py Wyświetl plik

@@ -18,11 +18,6 @@ class TestSwisscowsEngine(SearxTestCase):
18 18
         self.assertTrue('uiLanguage=de' in params['url'])
19 19
         self.assertTrue('region=de-DE' in params['url'])
20 20
 
21
-        dicto['language'] = 'all'
22
-        params = swisscows.request(query, dicto)
23
-        self.assertTrue('uiLanguage=browser' in params['url'])
24
-        self.assertTrue('region=browser' in params['url'])
25
-
26 21
         dicto['category'] = 'images'
27 22
         params = swisscows.request(query, dicto)
28 23
         self.assertIn('image', params['url'])

+ 0
- 6
tests/unit/engines/test_twitter.py Wyświetl plik

@@ -20,12 +20,6 @@ class TestTwitterEngine(SearxTestCase):
20 20
         self.assertIn('lang', params['cookies'])
21 21
         self.assertIn('fr', params['cookies']['lang'])
22 22
 
23
-        dicto['language'] = 'all'
24
-        params = twitter.request(query, dicto)
25
-        self.assertIn('cookies', params)
26
-        self.assertIn('lang', params['cookies'])
27
-        self.assertIn('en', params['cookies']['lang'])
28
-
29 23
     def test_response(self):
30 24
         self.assertRaises(AttributeError, twitter.response, None)
31 25
         self.assertRaises(AttributeError, twitter.response, [])

+ 3
- 3
tests/unit/engines/test_wikidata.py Wyświetl plik

@@ -11,14 +11,14 @@ class TestWikidataEngine(SearxTestCase):
11 11
     def test_request(self):
12 12
         query = 'test_query'
13 13
         dicto = defaultdict(dict)
14
-        dicto['language'] = 'all'
14
+        dicto['language'] = 'en-US'
15 15
         params = wikidata.request(query, dicto)
16 16
         self.assertIn('url', params)
17 17
         self.assertIn(query, params['url'])
18 18
         self.assertIn('wikidata.org', params['url'])
19 19
         self.assertIn('en', params['url'])
20 20
 
21
-        dicto['language'] = 'es_ES'
21
+        dicto['language'] = 'es-ES'
22 22
         params = wikidata.request(query, dicto)
23 23
         self.assertIn(query, params['url'])
24 24
         self.assertIn('es', params['url'])
@@ -30,7 +30,7 @@ class TestWikidataEngine(SearxTestCase):
30 30
         self.assertRaises(AttributeError, wikidata.response, '')
31 31
         self.assertRaises(AttributeError, wikidata.response, '[]')
32 32
 
33
-        response = mock.Mock(text='<html></html>', search_params={"language": "all"})
33
+        response = mock.Mock(text='<html></html>', search_params={"language": "en"})
34 34
         self.assertEqual(wikidata.response(response), [])
35 35
 
36 36
     def test_getDetail(self):

+ 0
- 4
tests/unit/engines/test_wikipedia.py Wyświetl plik

@@ -25,10 +25,6 @@ class TestWikipediaEngine(SearxTestCase):
25 25
         self.assertIn('Test_Query', params['url'])
26 26
         self.assertNotIn('test_query', params['url'])
27 27
 
28
-        dicto['language'] = 'all'
29
-        params = wikipedia.request(query, dicto)
30
-        self.assertIn('en', params['url'])
31
-
32 28
         dicto['language'] = 'xx'
33 29
         params = wikipedia.request(query, dicto)
34 30
         self.assertIn('en', params['url'])

+ 0
- 5
tests/unit/engines/test_yacy.py Wyświetl plik

@@ -17,11 +17,6 @@ class TestYacyEngine(SearxTestCase):
17 17
         self.assertIn('localhost', params['url'])
18 18
         self.assertIn('fr', params['url'])
19 19
 
20
-        dicto['language'] = 'all'
21
-        params = yacy.request(query, dicto)
22
-        self.assertIn('url', params)
23
-        self.assertNotIn('lr=lang_', params['url'])
24
-
25 20
     def test_response(self):
26 21
         self.assertRaises(AttributeError, yacy.response, None)
27 22
         self.assertRaises(AttributeError, yacy.response, [])

+ 0
- 7
tests/unit/engines/test_yahoo.py Wyświetl plik

@@ -39,13 +39,6 @@ class TestYahooEngine(SearxTestCase):
39 39
         self.assertIn('sB', params['cookies'])
40 40
         self.assertIn('fr', params['cookies']['sB'])
41 41
 
42
-        dicto['language'] = 'all'
43
-        params = yahoo.request(query, dicto)
44
-        self.assertIn('cookies', params)
45
-        self.assertIn('sB', params['cookies'])
46
-        self.assertIn('en', params['cookies']['sB'])
47
-        self.assertIn('en', params['url'])
48
-
49 42
     def test_no_url_in_request_year_time_range(self):
50 43
         dicto = defaultdict(dict)
51 44
         query = 'test_query'

+ 0
- 7
tests/unit/engines/test_yahoo_news.py Wyświetl plik

@@ -22,13 +22,6 @@ class TestYahooNewsEngine(SearxTestCase):
22 22
         self.assertIn('sB', params['cookies'])
23 23
         self.assertIn('fr', params['cookies']['sB'])
24 24
 
25
-        dicto['language'] = 'all'
26
-        params = yahoo_news.request(query, dicto)
27
-        self.assertIn('cookies', params)
28
-        self.assertIn('sB', params['cookies'])
29
-        self.assertIn('en', params['cookies']['sB'])
30
-        self.assertIn('en', params['url'])
31
-
32 25
     def test_sanitize_url(self):
33 26
         url = "test.url"
34 27
         self.assertEqual(url, yahoo_news.sanitize_url(url))

+ 10
- 5
tests/unit/test_preferences.py Wyświetl plik

@@ -90,25 +90,30 @@ class TestSettings(SearxTestCase):
90 90
 
91 91
     # search language settings
92 92
     def test_lang_setting_valid_choice(self):
93
-        setting = SearchLanguageSetting('all', choices=['all', 'de', 'en'])
93
+        setting = SearchLanguageSetting('en', choices=['de', 'en'])
94 94
         setting.parse('de')
95 95
         self.assertEquals(setting.get_value(), 'de')
96 96
 
97 97
     def test_lang_setting_invalid_choice(self):
98
-        setting = SearchLanguageSetting('all', choices=['all', 'de', 'en'])
98
+        setting = SearchLanguageSetting('en', choices=['de', 'en'])
99 99
         setting.parse('xx')
100
-        self.assertEquals(setting.get_value(), 'all')
100
+        self.assertEquals(setting.get_value(), 'en')
101 101
 
102 102
     def test_lang_setting_old_cookie_choice(self):
103
-        setting = SearchLanguageSetting('all', choices=['all', 'es', 'es-ES'])
103
+        setting = SearchLanguageSetting('en', choices=['en', 'es', 'es-ES'])
104 104
         setting.parse('es_XA')
105 105
         self.assertEquals(setting.get_value(), 'es')
106 106
 
107 107
     def test_lang_setting_old_cookie_format(self):
108
-        setting = SearchLanguageSetting('all', choices=['all', 'es', 'es-ES'])
108
+        setting = SearchLanguageSetting('en', choices=['en', 'es', 'es-ES'])
109 109
         setting.parse('es_ES')
110 110
         self.assertEquals(setting.get_value(), 'es-ES')
111 111
 
112
+    def test_lang_setting_old_default(self):
113
+        setting = SearchLanguageSetting('en', choices=['en', 'es', 'de'])
114
+        setting.parse('all')
115
+        self.assertEquals(setting.get_value(), 'en')
116
+
112 117
     # plugins settings
113 118
     def test_plugins_setting_all_default_enabled(self):
114 119
         plugin1 = PluginStub('plugin1', True)

+ 64
- 0
tests/unit/test_query.py Wyświetl plik

@@ -0,0 +1,64 @@
1
+from searx.query import RawTextQuery
2
+from searx.testing import SearxTestCase
3
+
4
+
5
+class TestQuery(SearxTestCase):
6
+
7
+    def test_simple_query(self):
8
+        query_text = 'the query'
9
+        query = RawTextQuery(query_text, [])
10
+        query.parse_query()
11
+
12
+        self.assertEquals(query.getFullQuery(), query_text)
13
+        self.assertEquals(len(query.query_parts), 1)
14
+        self.assertEquals(len(query.languages), 0)
15
+        self.assertFalse(query.specific)
16
+
17
+    def test_language_code(self):
18
+        language = 'es-ES'
19
+        query_text = 'the query'
20
+        full_query = ':' + language + ' ' + query_text
21
+        query = RawTextQuery(full_query, [])
22
+        query.parse_query()
23
+
24
+        self.assertEquals(query.getFullQuery(), full_query)
25
+        self.assertEquals(len(query.query_parts), 3)
26
+        self.assertEquals(len(query.languages), 1)
27
+        self.assertIn(language, query.languages)
28
+        self.assertFalse(query.specific)
29
+
30
+    def test_language_name(self):
31
+        language = 'english'
32
+        query_text = 'the query'
33
+        full_query = ':' + language + ' ' + query_text
34
+        query = RawTextQuery(full_query, [])
35
+        query.parse_query()
36
+
37
+        self.assertEquals(query.getFullQuery(), full_query)
38
+        self.assertEquals(len(query.query_parts), 3)
39
+        self.assertIn('en', query.languages)
40
+        self.assertFalse(query.specific)
41
+
42
+    def test_unlisted_language_code(self):
43
+        language = 'all'
44
+        query_text = 'the query'
45
+        full_query = ':' + language + ' ' + query_text
46
+        query = RawTextQuery(full_query, [])
47
+        query.parse_query()
48
+
49
+        self.assertEquals(query.getFullQuery(), full_query)
50
+        self.assertEquals(len(query.query_parts), 3)
51
+        self.assertIn('all', query.languages)
52
+        self.assertFalse(query.specific)
53
+
54
+    def test_invalid_language_code(self):
55
+        language = 'not_a_language'
56
+        query_text = 'the query'
57
+        full_query = ':' + language + ' ' + query_text
58
+        query = RawTextQuery(full_query, [])
59
+        query.parse_query()
60
+
61
+        self.assertEquals(query.getFullQuery(), full_query)
62
+        self.assertEquals(len(query.query_parts), 1)
63
+        self.assertEquals(len(query.languages), 0)
64
+        self.assertFalse(query.specific)