summaryrefslogtreecommitdiff
path: root/searx/engines/yacy.py
blob: efdf846ac056e4a7f1f7127fa4c46674dbd218e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from json import loads
from urllib import urlencode

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 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 result['description']:
            tmp_result['content'] += result['description'] + "<br/>"

        if result['pubDate']:
            tmp_result['content'] += result['pubDate'] + "<br/>"

        if result['size'] != '-1':
            tmp_result['content'] += result['sizename']

        results.append(tmp_result)

    return results