mirror of https://github.com/searxng/searxng.git
[fix] bing paging and language support
see https://msdn.microsoft.com/en-us/library/ff795620.aspx for bing specific search operators closes #755
This commit is contained in:
parent
7d26b3f8f8
commit
16ff8d06c7
|
@ -32,18 +32,13 @@ search_string = 'search?{query}&first={offset}'
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
offset = (params['pageno'] - 1) * 10 + 1
|
offset = (params['pageno'] - 1) * 10 + 1
|
||||||
|
|
||||||
if params['language'] == 'all':
|
if params['language'] != 'all':
|
||||||
language = 'en-US'
|
query = 'language:{} {}'.format(params['language'].split('_')[0].upper(), query)
|
||||||
else:
|
|
||||||
language = params['language'].replace('_', '-')
|
|
||||||
|
|
||||||
search_path = search_string.format(
|
search_path = search_string.format(
|
||||||
query=urlencode({'q': query, 'setmkt': language}),
|
query=urlencode({'q': query}),
|
||||||
offset=offset)
|
offset=offset)
|
||||||
|
|
||||||
params['cookies']['SRCHHPGUSR'] = \
|
|
||||||
'NEWWND=0&NRSLT=-1&SRCHLANG=' + language.split('-')[0]
|
|
||||||
|
|
||||||
params['url'] = base_url + search_path
|
params['url'] = base_url + search_path
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
|
|
@ -14,14 +14,12 @@ class TestBingEngine(SearxTestCase):
|
||||||
params = bing.request(query, dicto)
|
params = bing.request(query, dicto)
|
||||||
self.assertTrue('url' in params)
|
self.assertTrue('url' in params)
|
||||||
self.assertTrue(query in params['url'])
|
self.assertTrue(query in params['url'])
|
||||||
|
self.assertTrue('language%3AFR' in params['url'])
|
||||||
self.assertTrue('bing.com' 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'
|
dicto['language'] = 'all'
|
||||||
params = bing.request(query, dicto)
|
params = bing.request(query, dicto)
|
||||||
self.assertTrue('SRCHHPGUSR' in params['cookies'])
|
self.assertTrue('language' not in params['url'])
|
||||||
self.assertTrue('en' in params['cookies']['SRCHHPGUSR'])
|
|
||||||
|
|
||||||
def test_response(self):
|
def test_response(self):
|
||||||
self.assertRaises(AttributeError, bing.response, None)
|
self.assertRaises(AttributeError, bing.response, None)
|
||||||
|
|
Loading…
Reference in New Issue