on master help sign in
Merge pull request #1273 from MarcAbonce/google-hotfix

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

commite6aaf20898240a6fdc97490f6d522e0ddb839a49 authorAdam Tauber <asciimoo@gmail.com> dateFri 20 Apr 2018, 19:45 (9 years ago) parent49b6206f7f9c50
2 files changed+7−7
searx/engines/google.py+3−6 tests/unit/engines/test_google.py+4−1
searx/engines/google.py+3−6
@@ -91,7 +91,7 @@ url_map = 'https://www.openstreetmap.org/'\
9191search_path = '/search'
9292search_url = ('https://{hostname}' +
9393 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')
9595
9696time_range_search = "&tbs=qdr:{range}"
9797time_range_dict = {'day': 'd',
@@ -175,10 +175,6 @@ def request(query, params):
175175 else:
176176 country = 'US'
177177
178− # temporary fix until a way of supporting en-US is found
179− if language == 'en-US':
180− country = 'GB'
181−
182178 url_lang = 'lang_' + language
183179
184180 if use_locale_domain:
@@ -191,7 +187,8 @@ def request(query, params):
191187 params['url'] = search_url.format(offset=offset,
192188 query=urlencode({'q': query}),
193189 hostname=google_hostname,
194− lang=url_lang)
190+ lang=url_lang,
191+ lang_short=language)
195192 if params['time_range'] in time_range_dict:
196193 params['url'] += time_range_search.format(range=time_range_dict[params['time_range']])
197194
tests/unit/engines/test_google.py+4−1
@@ -26,16 +26,19 @@ class TestGoogleEngine(SearxTestCase):
2626 self.assertIn('url', params)
2727 self.assertIn(query, params['url'])
2828 self.assertIn('google.fr', params['url'])
29+ self.assertIn('fr', params['url'])
2930 self.assertIn('fr', params['headers']['Accept-Language'])
3031
3132 dicto['language'] = 'en-US'
3233 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'])
3436 self.assertIn('en', params['headers']['Accept-Language'])
3537
3638 dicto['language'] = 'zh'
3739 params = google.request(query, dicto)
3840 self.assertIn('google.com', params['url'])
41+ self.assertIn('zh-CN', params['url'])
3942 self.assertIn('zh-CN', params['headers']['Accept-Language'])
4043
4144 def test_response(self):