aboutsummaryrefslogtreecommitdiff
path: root/src/khanindexer-nevrax.py
blob: e5dc66dbc30817243f7ec873dad4d056b22420e2 (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
41
42
43
44
45
46
47
48
49
50
# khanindexer
#
# @website     https://git.khaganat.net/neodarz/khanindexer
#
# @results     JSON
# @stable      yes
# @parse       (general)    url, title, content

from urllib import urlencode
import json

# engine dependent config
categories = ['general']  # TODO , 'images', 'music', 'videos', 'files'
paging = False
language_support = False
number_of_results = 5

# search-url
base_url = 'http://127.0.0.1:5000/?index=nevrax'
search_url = '&{query}'


# do search-request
def request(query, params):

    params['url'] = base_url +\
            search_url.format(query=urlencode({'search': query}))

    print(params['url'])
    return params


# get response from search-request
def response(resp):
    results = []

    datas = json.loads(resp.text)

    if not 'error' in datas:
        for el in datas:
             results.append({
                 'title': el['title'],
                 'content': el['excerpts'][0],
                 'url': el['url']
            })
    else:
        print("ERROR:Search server: "+str(datas['msg']))

    # return results
    return results