Bladeren bron

[fix] fix duckduckgo's offset

First page now starts with 0 offset,
rather than starting on the 30th result.

DuckDuckGo returns 30 results on each page.
marc 7 jaren geleden
bovenliggende
commit
3b950929b1
2 gewijzigde bestanden met toevoegingen van 4 en 4 verwijderingen
  1. 3
    4
      searx/engines/duckduckgo.py
  2. 1
    0
      tests/unit/engines/test_duckduckgo.py

+ 3
- 4
searx/engines/duckduckgo.py Bestand weergeven

@@ -79,16 +79,15 @@ def request(query, params):
79 79
     if params['time_range'] and params['time_range'] not in time_range_dict:
80 80
         return params
81 81
 
82
-    offset = 30 + (params['pageno'] - 1) * 50
83
-    dc_param = offset + 1
82
+    offset = (params['pageno'] - 1) * 30
84 83
 
85 84
     region_code = get_region_code(params['language'])
86 85
     if region_code:
87 86
         params['url'] = url.format(
88
-            query=urlencode({'q': query, 'kl': region_code}), offset=offset, dc_param=dc_param)
87
+            query=urlencode({'q': query, 'kl': region_code}), offset=offset, dc_param=offset)
89 88
     else:
90 89
         params['url'] = url.format(
91
-            query=urlencode({'q': query}), offset=offset, dc_param=dc_param)
90
+            query=urlencode({'q': query}), offset=offset, dc_param=offset)
92 91
 
93 92
     if params['time_range'] in time_range_dict:
94 93
         params['url'] += time_range_url.format(range=time_range_dict[params['time_range']])

+ 1
- 0
tests/unit/engines/test_duckduckgo.py Bestand weergeven

@@ -18,6 +18,7 @@ class TestDuckduckgoEngine(SearxTestCase):
18 18
         self.assertIn(query, params['url'])
19 19
         self.assertIn('duckduckgo.com', params['url'])
20 20
         self.assertIn('ch-de', params['url'])
21
+        self.assertIn('s=0', params['url'])
21 22
 
22 23
         # when ddg uses non standard code
23 24
         dicto['language'] = 'en-GB'