forked from Ponysearch/Ponysearch
Merge pull request #1273 from MarcAbonce/google-hotfix
[fix] Force English results in Google when using en-US
This commit is contained in:
commit
e6aaf20898
2 changed files with 7 additions and 7 deletions
|
@ -91,7 +91,7 @@ url_map = 'https://www.openstreetmap.org/'\
|
||||||
search_path = '/search'
|
search_path = '/search'
|
||||||
search_url = ('https://{hostname}' +
|
search_url = ('https://{hostname}' +
|
||||||
search_path +
|
search_path +
|
||||||
'?{query}&start={offset}&gws_rd=cr&gbv=1&lr={lang}&ei=x')
|
'?{query}&start={offset}&gws_rd=cr&gbv=1&lr={lang}&hl={lang_short}&ei=x')
|
||||||
|
|
||||||
time_range_search = "&tbs=qdr:{range}"
|
time_range_search = "&tbs=qdr:{range}"
|
||||||
time_range_dict = {'day': 'd',
|
time_range_dict = {'day': 'd',
|
||||||
|
@ -175,10 +175,6 @@ def request(query, params):
|
||||||
else:
|
else:
|
||||||
country = 'US'
|
country = 'US'
|
||||||
|
|
||||||
# temporary fix until a way of supporting en-US is found
|
|
||||||
if language == 'en-US':
|
|
||||||
country = 'GB'
|
|
||||||
|
|
||||||
url_lang = 'lang_' + language
|
url_lang = 'lang_' + language
|
||||||
|
|
||||||
if use_locale_domain:
|
if use_locale_domain:
|
||||||
|
@ -191,7 +187,8 @@ def request(query, params):
|
||||||
params['url'] = search_url.format(offset=offset,
|
params['url'] = search_url.format(offset=offset,
|
||||||
query=urlencode({'q': query}),
|
query=urlencode({'q': query}),
|
||||||
hostname=google_hostname,
|
hostname=google_hostname,
|
||||||
lang=url_lang)
|
lang=url_lang,
|
||||||
|
lang_short=language)
|
||||||
if params['time_range'] in time_range_dict:
|
if params['time_range'] in time_range_dict:
|
||||||
params['url'] += time_range_search.format(range=time_range_dict[params['time_range']])
|
params['url'] += time_range_search.format(range=time_range_dict[params['time_range']])
|
||||||
|
|
||||||
|
|
|
@ -26,16 +26,19 @@ class TestGoogleEngine(SearxTestCase):
|
||||||
self.assertIn('url', params)
|
self.assertIn('url', params)
|
||||||
self.assertIn(query, params['url'])
|
self.assertIn(query, params['url'])
|
||||||
self.assertIn('google.fr', params['url'])
|
self.assertIn('google.fr', params['url'])
|
||||||
|
self.assertIn('fr', params['url'])
|
||||||
self.assertIn('fr', params['headers']['Accept-Language'])
|
self.assertIn('fr', params['headers']['Accept-Language'])
|
||||||
|
|
||||||
dicto['language'] = 'en-US'
|
dicto['language'] = 'en-US'
|
||||||
params = google.request(query, dicto)
|
params = google.request(query, dicto)
|
||||||
self.assertIn('google.co', params['url'])
|
self.assertIn('google.com', params['url'])
|
||||||
|
self.assertIn('en', params['url'])
|
||||||
self.assertIn('en', params['headers']['Accept-Language'])
|
self.assertIn('en', params['headers']['Accept-Language'])
|
||||||
|
|
||||||
dicto['language'] = 'zh'
|
dicto['language'] = 'zh'
|
||||||
params = google.request(query, dicto)
|
params = google.request(query, dicto)
|
||||||
self.assertIn('google.com', params['url'])
|
self.assertIn('google.com', params['url'])
|
||||||
|
self.assertIn('zh-CN', params['url'])
|
||||||
self.assertIn('zh-CN', params['headers']['Accept-Language'])
|
self.assertIn('zh-CN', params['headers']['Accept-Language'])
|
||||||
|
|
||||||
def test_response(self):
|
def test_response(self):
|
||||||
|
|
Loading…
Reference in a new issue