Przeglądaj źródła

[fix] bing paging and language support

see https://msdn.microsoft.com/en-us/library/ff795620.aspx for bing
specific search operators

closes #755
Adam Tauber 8 lat temu
rodzic
commit
16ff8d06c7
2 zmienionych plików z 5 dodań i 12 usunięć
  1. 3
    8
      searx/engines/bing.py
  2. 2
    4
      tests/unit/engines/test_bing.py

+ 3
- 8
searx/engines/bing.py Wyświetl plik

@@ -32,18 +32,13 @@ search_string = 'search?{query}&first={offset}'
32 32
 def request(query, params):
33 33
     offset = (params['pageno'] - 1) * 10 + 1
34 34
 
35
-    if params['language'] == 'all':
36
-        language = 'en-US'
37
-    else:
38
-        language = params['language'].replace('_', '-')
35
+    if params['language'] != 'all':
36
+        query = 'language:{} {}'.format(params['language'].split('_')[0].upper(), query)
39 37
 
40 38
     search_path = search_string.format(
41
-        query=urlencode({'q': query, 'setmkt': language}),
39
+        query=urlencode({'q': query}),
42 40
         offset=offset)
43 41
 
44
-    params['cookies']['SRCHHPGUSR'] = \
45
-        'NEWWND=0&NRSLT=-1&SRCHLANG=' + language.split('-')[0]
46
-
47 42
     params['url'] = base_url + search_path
48 43
     return params
49 44
 

+ 2
- 4
tests/unit/engines/test_bing.py Wyświetl plik

@@ -14,14 +14,12 @@ class TestBingEngine(SearxTestCase):
14 14
         params = bing.request(query, dicto)
15 15
         self.assertTrue('url' in params)
16 16
         self.assertTrue(query in params['url'])
17
+        self.assertTrue('language%3AFR' in params['url'])
17 18
         self.assertTrue('bing.com' in params['url'])
18
-        self.assertTrue('SRCHHPGUSR' in params['cookies'])
19
-        self.assertTrue('fr' in params['cookies']['SRCHHPGUSR'])
20 19
 
21 20
         dicto['language'] = 'all'
22 21
         params = bing.request(query, dicto)
23
-        self.assertTrue('SRCHHPGUSR' in params['cookies'])
24
-        self.assertTrue('en' in params['cookies']['SRCHHPGUSR'])
22
+        self.assertTrue('language' not in params['url'])
25 23
 
26 24
     def test_response(self):
27 25
         self.assertRaises(AttributeError, bing.response, None)