From 8a69ade875e238579308d1efb769c5e5cb367b47 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Fri, 1 May 2015 21:20:09 +0200 Subject: [PATCH 1/2] Revert of #195 when the search language is not english Sometimes there is two requests to google (depending of the source IP) : one to google.com, the second to google.fr (for instance). Going to https://www.google.com/ncr and saving the PREF cookie for future use prevent this (there is no redirection). But, recently (or not ?), by doing this the search returns English results even if the Accept-Language is specified. There is still a way to prevent this : going to preference, set the search language. I don't know if this can be done by searx. For now, a quick fix is to disable the use of the PREF cookie when the search language is not English (google engine will slower but returns excepted results). --- searx/engines/google.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/searx/engines/google.py b/searx/engines/google.py index 9c768260a..807c58ed5 100644 --- a/searx/engines/google.py +++ b/searx/engines/google.py @@ -76,7 +76,8 @@ def request(query, params): query=urlencode({'q': query})) params['headers']['Accept-Language'] = language - params['cookies']['PREF'] = get_google_pref_cookie() + if language.startswith('en'): + params['cookies']['PREF'] = get_google_pref_cookie() return params From 65e6737413ee1cc27348258ff1586c98bf38da37 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Sat, 2 May 2015 13:21:01 +0200 Subject: [PATCH 2/2] [fix] google engine tests --- searx/tests/engines/test_google.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/searx/tests/engines/test_google.py b/searx/tests/engines/test_google.py index 2c3d8e5f6..2a90fc5ec 100644 --- a/searx/tests/engines/test_google.py +++ b/searx/tests/engines/test_google.py @@ -17,12 +17,13 @@ class TestGoogleEngine(SearxTestCase): self.assertIn('url', params) self.assertIn(query, params['url']) self.assertIn('google.com', params['url']) - self.assertIn('PREF', params['cookies']) + self.assertNotIn('PREF', params['cookies']) self.assertIn('fr', params['headers']['Accept-Language']) dicto['language'] = 'all' params = google.request(query, dicto) self.assertIn('en', params['headers']['Accept-Language']) + self.assertIn('PREF', params['cookies']) def test_response(self): self.assertRaises(AttributeError, google.response, None)