Преглед изворни кода

[fix] force English results in Google when using en-US

Marc Abonce Seguin пре 6 година
родитељ
комит
f7f9c50393
2 измењених фајлова са 7 додато и 7 уклоњено
  1. 3
    6
      searx/engines/google.py
  2. 4
    1
      tests/unit/engines/test_google.py

+ 3
- 6
searx/engines/google.py Прегледај датотеку

@@ -91,7 +91,7 @@ url_map = 'https://www.openstreetmap.org/'\
91 91
 search_path = '/search'
92 92
 search_url = ('https://{hostname}' +
93 93
               search_path +
94
-              '?{query}&start={offset}&gws_rd=cr&gbv=1&lr={lang}&ei=x')
94
+              '?{query}&start={offset}&gws_rd=cr&gbv=1&lr={lang}&hl={lang_short}&ei=x')
95 95
 
96 96
 time_range_search = "&tbs=qdr:{range}"
97 97
 time_range_dict = {'day': 'd',
@@ -175,10 +175,6 @@ def request(query, params):
175 175
     else:
176 176
         country = 'US'
177 177
 
178
-    # temporary fix until a way of supporting en-US is found
179
-    if language == 'en-US':
180
-        country = 'GB'
181
-
182 178
     url_lang = 'lang_' + language
183 179
 
184 180
     if use_locale_domain:
@@ -191,7 +187,8 @@ def request(query, params):
191 187
     params['url'] = search_url.format(offset=offset,
192 188
                                       query=urlencode({'q': query}),
193 189
                                       hostname=google_hostname,
194
-                                      lang=url_lang)
190
+                                      lang=url_lang,
191
+                                      lang_short=language)
195 192
     if params['time_range'] in time_range_dict:
196 193
         params['url'] += time_range_search.format(range=time_range_dict[params['time_range']])
197 194
 

+ 4
- 1
tests/unit/engines/test_google.py Прегледај датотеку

@@ -26,16 +26,19 @@ class TestGoogleEngine(SearxTestCase):
26 26
         self.assertIn('url', params)
27 27
         self.assertIn(query, params['url'])
28 28
         self.assertIn('google.fr', params['url'])
29
+        self.assertIn('fr', params['url'])
29 30
         self.assertIn('fr', params['headers']['Accept-Language'])
30 31
 
31 32
         dicto['language'] = 'en-US'
32 33
         params = google.request(query, dicto)
33
-        self.assertIn('google.co', params['url'])
34
+        self.assertIn('google.com', params['url'])
35
+        self.assertIn('en', params['url'])
34 36
         self.assertIn('en', params['headers']['Accept-Language'])
35 37
 
36 38
         dicto['language'] = 'zh'
37 39
         params = google.request(query, dicto)
38 40
         self.assertIn('google.com', params['url'])
41
+        self.assertIn('zh-CN', params['url'])
39 42
         self.assertIn('zh-CN', params['headers']['Accept-Language'])
40 43
 
41 44
     def test_response(self):