Commit af04ab30 authored by 段英荣's avatar 段英荣

add

parent 17f7c3c7
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import, print_function
from gm_rpcd.all import bind
import logging
import traceback
import json
from libs.es import ESPerform
from libs.cache import redis_client
def get_suggest_tips(query,offset=0,size=100):
try:
q = {
"suggest":{
"tips-suggest": {
"prefix": query,
"completion": {
"field": "suggest"
}
}
},
"sort": [
{"offline_score": {"order": "desc"}}
],
"_source": {
"include": ["id", "ori_name", "offline_score", "is_online"]
}
}
ret_list = list()
result_dict = ESPerform.get_search_results(ESPerform.get_cli(),sub_index_name="tag",query_body=q,offset=offset,size=size,is_suggest_request=True)
for tips_item in result_dict["suggest"]["tips-suggest"]:
for hit_item in tips_item["options"]:
ret_list.append(hit_item["_source"])
return ret_list
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return list()
......@@ -9,30 +9,33 @@ import json
from libs.es import ESPerform
from libs.cache import redis_client
from libs.tools import json_http_response
from search.utils.auto_tips import get_suggest_tips
def auto_complete(request):
"""auto complate words/tags/doctors etc.
URL:
~/api/auto_complete?scope=[kw]&q=双
Return:
{'error': 0|1, 'data': [word, word, word],}
"""
q = request.GET.get('q', '').strip()
if not q:
return json_http_response({'error': 0, 'data': []})
data = list()
result = {
'error': 0,
'data': data,
}
return json_http_response(result)
try:
"""auto complate words/tags/doctors etc.
URL:
~/api/auto_complete?scope=[kw]&q=双
Return:
{'error': 0|1, 'data': [word, word, word],}
"""
q = request.GET.get('q', '').strip()
if not q:
return json_http_response({'error': 0, 'data': []})
data = get_suggest_tips(q)
result = {
'error': 0,
'data': data,
}
return json_http_response(result)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return json_http_response({'error': 1, 'data': []})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment