Browse Source

Merge branch 'master' into add_ccctv_to_settings

Stefan Antoni 8 years ago
parent
commit
e6d69b082f
2 changed files with 66 additions and 0 deletions
  1. 57
    0
      searx/engines/searx_engine.py
  2. 9
    0
      searx/settings.yml

+ 57
- 0
searx/engines/searx_engine.py View File

@@ -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

+ 9
- 0
searx/settings.yml View File

@@ -174,6 +174,7 @@ engines:
174 174
     suggestion_xpath : //a[@class="crossreference"]
175 175
     first_page_num : 0
176 176
     shortcut : et
177
+    disabled : True
177 178
 
178 179
 # api-key required: http://www.faroo.com/hp/api/api.html#key
179 180
 #  - name : faroo
@@ -451,6 +452,14 @@ engines:
451 452
     shortcut : scc
452 453
     disabled : True
453 454
 
455
+#  - name : searx
456
+#    engine : searx_engine
457
+#    shortcut : se
458
+#    instance_urls :
459
+#        - http://127.0.0.1:8888/
460
+#        - ...
461
+#    disabled : True
462
+
454 463
   - name : spotify
455 464
     engine : spotify
456 465
     shortcut : stf