aboutsummaryrefslogtreecommitdiff
path: root/src/khanindexer.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/khanindexer.py')
-rw-r--r--src/khanindexer.py37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/khanindexer.py b/src/khanindexer.py
index 05a5602..36dd1ef 100644
--- a/src/khanindexer.py
+++ b/src/khanindexer.py
@@ -15,16 +15,27 @@ paging = False
language_support = False
number_of_results = 5
-# search-url
-base_url = 'http://127.0.0.1:5000/?index=neodarznet'
-search_url = '&{query}'
-
-
# do search-request
def request(query, params):
- params['url'] = base_url +\
- search_url.format(query=urlencode({'search': query}))
+ params['data'] = json.dumps({
+ "index": "neodarznet",
+ "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
@@ -36,14 +47,14 @@ def response(resp):
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']
+ 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['msg']))
+ print("ERROR:Search server: "+str(datas['error']))
# return results
return results