aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/khanindexer-nevrax.py38
-rw-r--r--src/khanindexer.py37
2 files changed, 48 insertions, 27 deletions
diff --git a/src/khanindexer-nevrax.py b/src/khanindexer-nevrax.py
index e5dc66d..326c95c 100644
--- a/src/khanindexer-nevrax.py
+++ b/src/khanindexer-nevrax.py
@@ -15,18 +15,28 @@ 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}))
+ 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'
- print(params['url'])
return params
@@ -37,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
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