Commit 58e44888 authored by 李小芳's avatar 李小芳

Merge branch 'wordres' into 'master'

Wordres

See merge request !28
parents 0db0bc46 9653ed9f
...@@ -100,6 +100,8 @@ class QueryWordAttr(object): ...@@ -100,6 +100,8 @@ class QueryWordAttr(object):
key = cls.tips_num_redis_key_prefix + str(id) key = cls.tips_num_redis_key_prefix + str(id)
results_num = redis_client.get(key) results_num = redis_client.get(key)
# results_num = json.loads(str(redis_data, encoding="utf-8")) if redis_data else {} # results_num = json.loads(str(redis_data, encoding="utf-8")) if redis_data else {}
if results_num == None:
results_num = 0
return int(results_num) return int(results_num)
except: except:
......
...@@ -165,28 +165,49 @@ def get_suggest_tips(query, lat, lng, offset=0, size=50): ...@@ -165,28 +165,49 @@ def get_suggest_tips(query, lat, lng, offset=0, size=50):
ret_list.extend(get_tag_wiki_data) ret_list.extend(get_tag_wiki_data)
ret_list.extend(get_doctor_hospital_data) ret_list.extend(get_doctor_hospital_data)
logging.info("get have_read_tips_set:%s" % have_read_tips_set)
if len(result_dict["suggest"]["tips-suggest"]) >= 50: if len(result_dict["suggest"]["tips-suggest"]) >= 50:
return ret_list return ret_list
else: else:
QUERY_KEY = "query:{}:search_tip" query_ret_list = []
wordresemble_ret_list = []
value_data = []
QUERY_KEY = "query:search_tip"
query_base64 = base64.b64encode(query.encode('utf8')).decode('utf8') query_base64 = base64.b64encode(query.encode('utf8')).decode('utf8')
key = QUERY_KEY.format(query_base64) if redis_client.hget(QUERY_KEY, query_base64) is not None:
labels = list(map(lambda x: x.decode("utf8"), list(redis_client.smembers(key)))) value_data = json.loads(redis_client.hget(QUERY_KEY, query_base64))
for i in labels: logging.info("get value_data:%s" % value_data)
ori = i.split(":")[0]
ori_name = base64.b64decode(ori.encode('utf8')).decode('utf8') if len(value_data) > 0:
if ori_name not in have_read_tips_set: for i in value_data:
have_read_tips_set.add(ori_name) key = list(i.keys())[0]
result_num = i.split(":")[1] ori_name = str(base64.b64decode(key), "utf-8")
ret_list.append( if ori_name not in have_read_tips_set:
{"results_num": result_num, "ori_name": ori_name, "id": None, "is_online": True, have_read_tips_set.add(ori_name)
"offline_score": 0, result_num = i.get(key, 0)
"type_flag": get_tips_word_type(ori_name), "highlight_name": ori_name, "describe": ""}) describe = "约" + str(result_num) + "个结果" if result_num else ""
logging.info("get result_num:%s" % result_num)
highlight_marks = u'<ems>%s</ems>' % query
highlight_name = ori_name.replace(query, highlight_marks)
if ori_name == query:
query_ret_list.append(
{"results_num": result_num, "ori_name": ori_name, "id": None, "is_online": True,
"offline_score": 0,
"type_flag": get_tips_word_type(ori_name), "highlight_name": highlight_name,
"describe": describe})
else:
wordresemble_ret_list.append(
{"results_num": result_num, "ori_name": ori_name, "id": None, "is_online": True,
"offline_score": 0,
"type_flag": get_tips_word_type(ori_name), "highlight_name": highlight_name,
"describe": describe})
logging.info("get query_ret_list:%s" % query_ret_list)
logging.info("get wordresemble_ret_list:%s" % wordresemble_ret_list)
ret_list.extend(query_ret_list)
ret_list.extend(wordresemble_ret_list)
if len(ret_list) >= 50: if len(ret_list) >= 50:
return ret_list[0:50] return ret_list[0:50]
else: else:
return ret_list return ret_list
......
No preview for this file type
...@@ -4,13 +4,13 @@ import os ...@@ -4,13 +4,13 @@ import os
import sys import sys
import logging import logging
import traceback import traceback
from libs.tools import tzlc,getMd5Digest from libs.tools import tzlc, getMd5Digest
from libs.es import ESPerform from libs.es import ESPerform
from libs.cache import redis_client from libs.cache import redis_client
import json import json
from trans2es.commons.commons import get_tips_suggest_list from trans2es.commons.commons import get_tips_suggest_list
from trans2es.commons.words_utils import QueryWordAttr,get_tips_word_type from trans2es.commons.words_utils import QueryWordAttr, get_tips_word_type
class ProduceWikiTransfer(object): class ProduceWikiTransfer(object):
...@@ -35,7 +35,7 @@ class ProduceWikiTransfer(object): ...@@ -35,7 +35,7 @@ class ProduceWikiTransfer(object):
suggest_list = get_tips_suggest_list(instance.name) suggest_list = get_tips_suggest_list(instance.name)
return (item_dict,suggest_list) return (item_dict, suggest_list)
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return ([],[]) return ([], [])
\ No newline at end of file
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