ソースを参照

add time range search for google

Noemi Vanyi 8 年 前
コミット
2e5839503f
共有1 個のファイルを変更した8 個の追加0 個の削除を含む
  1. 8
    0
      searx/engines/google.py

+ 8
- 0
searx/engines/google.py ファイルの表示

24
 paging = True
24
 paging = True
25
 language_support = True
25
 language_support = True
26
 use_locale_domain = True
26
 use_locale_domain = True
27
+time_range_support = True
27
 
28
 
28
 # based on https://en.wikipedia.org/wiki/List_of_Google_domains and tests
29
 # based on https://en.wikipedia.org/wiki/List_of_Google_domains and tests
29
 default_hostname = 'www.google.com'
30
 default_hostname = 'www.google.com'
92
               search_path +
93
               search_path +
93
               '?{query}&start={offset}&gws_rd=cr&gbv=1&lr={lang}&ei=x')
94
               '?{query}&start={offset}&gws_rd=cr&gbv=1&lr={lang}&ei=x')
94
 
95
 
96
+time_range_search = "&tbs=qdr:{range}"
97
+time_range_dict = {'day': 'd',
98
+                   'week': 'w',
99
+                   'month': 'm'}
100
+
95
 # other URLs
101
 # other URLs
96
 map_hostname_start = 'maps.google.'
102
 map_hostname_start = 'maps.google.'
97
 maps_path = '/maps'
103
 maps_path = '/maps'
179
                                       query=urlencode({'q': query}),
185
                                       query=urlencode({'q': query}),
180
                                       hostname=google_hostname,
186
                                       hostname=google_hostname,
181
                                       lang=url_lang)
187
                                       lang=url_lang)
188
+    if params['time_range']:
189
+        params['url'] += time_range_search.format(range=time_range_dict[params['time_range']])
182
 
190
 
183
     params['headers']['Accept-Language'] = language
191
     params['headers']['Accept-Language'] = language
184
     params['headers']['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
192
     params['headers']['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'