From 16ff8d06c73d3e0ec784e8c9a1fb38b36a95d8fb Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Mon, 7 Nov 2016 22:30:20 +0100 Subject: [PATCH] [fix] bing paging and language support see https://msdn.microsoft.com/en-us/library/ff795620.aspx for bing specific search operators closes #755 --- searx/engines/bing.py | 11 +++-------- tests/unit/engines/test_bing.py | 6 ++---- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/searx/engines/bing.py b/searx/engines/bing.py index 6bdfd378b..b9c5f73fc 100644 --- a/searx/engines/bing.py +++ b/searx/engines/bing.py @@ -32,18 +32,13 @@ search_string = 'search?{query}&first={offset}' def request(query, params): offset = (params['pageno'] - 1) * 10 + 1 - if params['language'] == 'all': - language = 'en-US' - else: - language = params['language'].replace('_', '-') + if params['language'] != 'all': + query = 'language:{} {}'.format(params['language'].split('_')[0].upper(), query) search_path = search_string.format( - query=urlencode({'q': query, 'setmkt': language}), + query=urlencode({'q': query}), offset=offset) - params['cookies']['SRCHHPGUSR'] = \ - 'NEWWND=0&NRSLT=-1&SRCHLANG=' + language.split('-')[0] - params['url'] = base_url + search_path return params diff --git a/tests/unit/engines/test_bing.py b/tests/unit/engines/test_bing.py index bce221440..886584229 100644 --- a/tests/unit/engines/test_bing.py +++ b/tests/unit/engines/test_bing.py @@ -14,14 +14,12 @@ class TestBingEngine(SearxTestCase): params = bing.request(query, dicto) self.assertTrue('url' in params) self.assertTrue(query in params['url']) + self.assertTrue('language%3AFR' in params['url']) self.assertTrue('bing.com' in params['url']) - self.assertTrue('SRCHHPGUSR' in params['cookies']) - self.assertTrue('fr' in params['cookies']['SRCHHPGUSR']) dicto['language'] = 'all' params = bing.request(query, dicto) - self.assertTrue('SRCHHPGUSR' in params['cookies']) - self.assertTrue('en' in params['cookies']['SRCHHPGUSR']) + self.assertTrue('language' not in params['url']) def test_response(self): self.assertRaises(AttributeError, bing.response, None)