aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-01-20 10:46:13 +0100
committerneodarz <neodarz@neodarz.net>2019-01-20 10:46:13 +0100
commitc4f89d79f22d0e44b025cb2785ea8fd322c0fe43 (patch)
tree860d3e3184c7c92fcc652671b816204b92ef85ae
parentcfc6547fd7540234c21e177afb053510de8f8d6f (diff)
downloadryzomcore_searx-c4f89d79f22d0e44b025cb2785ea8fd322c0fe43.tar.xz
ryzomcore_searx-c4f89d79f22d0e44b025cb2785ea8fd322c0fe43.zip
Use Manticorsearch JSON API instead of custom search API
-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