summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpw3t <romain@berthor.fr>2013-12-29 21:39:23 +0100
committerpw3t <romain@berthor.fr>2013-12-29 21:39:23 +0100
commita492ca6dedc477655f5cfcfb67b845779b825348 (patch)
tree40f5aef3e3a6040b6299ba849bbb1131e92ac031
parent13c48a6d9b3db8f9d0439571f31e33ea8c8bd6f9 (diff)
[enh] add support for yacy engine (localhost)
-rw-r--r--searx/engines/yacy.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/searx/engines/yacy.py b/searx/engines/yacy.py
new file mode 100644
index 000000000..e24edde56
--- /dev/null
+++ b/searx/engines/yacy.py
@@ -0,0 +1,38 @@
+from json import loads
+from urllib import urlencode, quote
+
+url = 'http://localhost:8090'
+search_url = '/yacysearch.json?{query}&maximumRecords=10'
+
+def request(query, params):
+ params['url'] = url + search_url.format(query=urlencode({'query':query}))
+ return params
+
+def response(resp):
+ raw_search_results = loads(resp.text)
+
+ if not len(raw_search_results):
+ return []
+
+ search_results = raw_search_results.get('channels', {})[0].get('items', [])
+
+ results = []
+
+ for result in search_results:
+ tmp_result = {}
+ tmp_result['title'] = result['title']
+ tmp_result['url'] = result['link']
+ tmp_result['content'] = ''
+
+ if len(result['description']):
+ tmp_result['content'] += result['description'] +"<br/>"
+
+ if len(result['pubDate']):
+ tmp_result['content'] += result['pubDate'] + "<br/>"
+
+ if result['size'] != '-1':
+ tmp_result['content'] += result['sizename']
+
+ results.append(tmp_result)
+
+ return results