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
51
52
53
54
55
56
57
58
59
60
|
# 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
# do search-request
def request(query, params):
params['data'] = json.dumps({
"index": "nevrax",
"query": { "match": { "_all": query } },
"highlight":
{
"fields": {
"content": {},
"url": {},
"title": {}
},
"pre_tags": "_",
"post_tags": "_"
}
})
params['method'] = 'POST'
params['url'] = 'http://127.0.0.1:8080/json/search'
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['hits']['hits']:
results.append({
'title': el["_source"]["title"],
'content': el["highlight"]["content"][0],
'url': el["_source"]["url"]
})
else:
print("ERROR:Search server: "+str(datas['error']))
# return results
return results
|