aboutsummaryrefslogtreecommitdiff
path: root/sphinx/sphinx.py
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-01-20 00:24:49 +0100
committerneodarz <neodarz@neodarz.net>2019-01-20 00:32:27 +0100
commit5ffbc1172738e8ee26c934f4a82d2d3bbc3a5b37 (patch)
treeeca96ba661d1b6bf934abdf3bb0db23da6c7392f /sphinx/sphinx.py
parentaeaf4cb8cdd6d413cbd9e9d3c1156bd23bd0b386 (diff)
downloadkhanindexer-5ffbc1172738e8ee26c934f4a82d2d3bbc3a5b37.tar.xz
khanindexer-5ffbc1172738e8ee26c934f4a82d2d3bbc3a5b37.zip
Use Manticorsearch JSON API instead of custom search API
The migration is due to the fact that python use far more ressources that a simple JSON POST request directly on the Manticorsearch server.
Diffstat (limited to '')
-rw-r--r--sphinx/sphinx.py44
1 files changed, 0 insertions, 44 deletions
diff --git a/sphinx/sphinx.py b/sphinx/sphinx.py
deleted file mode 100644
index 11d3fee..0000000
--- a/sphinx/sphinx.py
+++ /dev/null
@@ -1,44 +0,0 @@
-from .sphinxapi import *
-
-import config
-
-sphinxclient = SphinxClient()
-
-sphinxclient.SetServer(host=config.SPHINX_HOST, port=config.SPHINX_PORT)
-
-def search(request, index):
- """
- Simple sphinx seach function, return a array of all documents matching the
- search terms.
- """
- status = sphinxclient.Status()
- response = {'error': 1, 'msg': 'Sphinx server not available'}
- if status != None:
- res = sphinxclient.Query(request, index)
-
- opts = {'before_match': '', 'after_match':'', 'chunk_separator': '...', 'limit': 400, 'around': 15}
-
- response = []
-
- if res != None:
- if 'matches' in res:
- n = 1
- for match in res['matches']:
- attrsdump = ''
- for attr in res['attrs']:
- attrname = attr[0]
- attrtype = attr[1]
- if attrname != "content":
- value = match['attrs'][attrname]
- if attrtype==SPH_ATTR_TIMESTAMP:
- value = time.strftime ( '%Y-%m-%d %H:%M:%S', time.localtime(value) )
- attrsdump = '%s, \'%s\'=\'%s\'' % ( attrsdump, attrname, value)
- docs = []
- docs.append(''.join([line.strip('\n') for line in match['attrs']['content']]))
- res_excerpts = sphinxclient.BuildExcerpts(index=index, docs=docs, opts=opts, words=request)
- response.append({'id': match['id'], 'weight': match['weight'], 'url': match['attrs']['url'], 'title': match['attrs']['title'], 'excerpts': res_excerpts})
- n += 1
- else:
- response = {'error': 1, 'msg': 'Maybe `'+str(index)+'` is not an index in the database?'}
-
- return response