Browse Source

[enh] add support for yacy engine (localhost)

pw3t 11 years ago
parent
commit
a492ca6ded
1 changed files with 38 additions and 0 deletions
  1. 38
    0
      searx/engines/yacy.py

+ 38
- 0
searx/engines/yacy.py View File

@@ -0,0 +1,38 @@
1
+from json import loads
2
+from urllib import urlencode, quote
3
+
4
+url = 'http://localhost:8090'
5
+search_url = '/yacysearch.json?{query}&maximumRecords=10'
6
+
7
+def request(query, params):
8
+    params['url'] = url + search_url.format(query=urlencode({'query':query}))
9
+    return params
10
+
11
+def response(resp):
12
+    raw_search_results = loads(resp.text)
13
+    
14
+    if not len(raw_search_results):
15
+        return []
16
+
17
+    search_results = raw_search_results.get('channels', {})[0].get('items', [])
18
+
19
+    results = []
20
+
21
+    for result in search_results:
22
+        tmp_result = {}
23
+        tmp_result['title'] = result['title']
24
+        tmp_result['url'] = result['link']
25
+        tmp_result['content'] = '' 
26
+        
27
+        if len(result['description']):
28
+            tmp_result['content'] += result['description'] +"<br/>" 
29
+
30
+        if len(result['pubDate']):
31
+            tmp_result['content'] += result['pubDate'] + "<br/>"
32
+
33
+        if result['size'] != '-1':
34
+            tmp_result['content'] += result['sizename']
35
+
36
+        results.append(tmp_result)
37
+
38
+    return results