Explorar el Código

[enh] add searx engine

Adam Tauber hace 8 años
padre
commit
b6fc154616
Se han modificado 2 ficheros con 65 adiciones y 0 borrados
  1. 57
    0
      searx/engines/searx_engine.py
  2. 8
    0
      searx/settings.yml

+ 57
- 0
searx/engines/searx_engine.py Ver fichero

@@ -0,0 +1,57 @@
1
+"""
2
+ Searx (all)
3
+
4
+ @website     https://github.com/asciimoo/searx
5
+ @provide-api yes (https://asciimoo.ithub.io/searx/dev/search_api.html)
6
+
7
+ @using-api   yes
8
+ @results     JSON
9
+ @stable      yes (using api)
10
+ @parse       url, title, content
11
+"""
12
+
13
+from json import loads
14
+from searx.engines import categories as searx_categories
15
+
16
+
17
+categories = searx_categories.keys()
18
+
19
+# search-url
20
+instance_urls = []
21
+instance_index = 0
22
+
23
+
24
+# do search-request
25
+def request(query, params):
26
+    global instance_index
27
+    params['url'] = instance_urls[instance_index % len(instance_urls)]
28
+    params['method'] = 'POST'
29
+
30
+    instance_index += 1
31
+
32
+    params['data'] = {
33
+        'q': query,
34
+        'pageno': params['pageno'],
35
+        'language': params['language'],
36
+        'time_range': params['time_range'],
37
+        'category': params['category'],
38
+        'format': 'json'
39
+    }
40
+
41
+    return params
42
+
43
+
44
+# get response from search-request
45
+def response(resp):
46
+
47
+    response_json = loads(resp.text)
48
+    results = response_json['results']
49
+
50
+    for i in ('answers', 'infoboxes'):
51
+        results.extend(response_json[i])
52
+
53
+    results.extend({'suggestion': s} for s in response_json['suggestions'])
54
+
55
+    results.append({'number_of_results': response_json['number_of_results']})
56
+
57
+    return results

+ 8
- 0
searx/settings.yml Ver fichero

@@ -441,6 +441,14 @@ engines:
441 441
     shortcut : scc
442 442
     disabled : True
443 443
 
444
+#  - name : searx
445
+#    engine : searx_engine
446
+#    shortcut : se
447
+#    instance_urls :
448
+#        - http://127.0.0.1:8888/
449
+#        - ...
450
+#    disabled : True
451
+
444 452
   - name : spotify
445 453
     engine : spotify
446 454
     shortcut : stf