Commit 65505254 authored by 李小芳's avatar 李小芳

Merge branch 'highlight' into 'master'

Highlight

See merge request !39
parents 2f6c7c4c 7a6e1e35
......@@ -114,6 +114,8 @@ def get_suggest_tips(query, lat, lng, offset=0, size=50):
get_tag_wiki_data = list()
have_read_tips_set = set()
ret_list = list()
doctor_hospital_equal_query = list()
tag_equal_query = list()
result_dict = ESPerform.get_search_results(ESPerform.get_cli(), sub_index_name="suggest", query_body=q,
offset=offset, size=size, is_suggest_request=True)
......@@ -148,17 +150,29 @@ def get_suggest_tips(query, lat, lng, offset=0, size=50):
else:
hit_item["_source"]["describe"] = ""
get_doctor_hospital_data.append(hit_item["_source"])
if hit_item["_source"]["ori_name"] == query:
doctor_hospital_equal_query.append(hit_item["_source"])
else:
get_doctor_hospital_data.append(hit_item["_source"])
else:
if hit_item["_source"]["type_flag"] == "doctor":
hit_item["_source"]["describe"] = ""
get_doctor_hospital_data.append(hit_item["_source"])
if hit_item["_source"]["ori_name"] == query:
doctor_hospital_equal_query.append(hit_item["_source"])
else:
get_doctor_hospital_data.append(hit_item["_source"])
else:
hit_item["_source"]["describe"] = "约" + str(hit_item["_source"]["results_num"]) + "个结果" if \
hit_item["_source"]["results_num"] else ""
get_tag_wiki_data.append(hit_item["_source"])
if hit_item["_source"]["ori_name"] == query:
tag_equal_query.append(hit_item["_source"])
else:
get_tag_wiki_data.append(hit_item["_source"])
ret_list.extend(tag_equal_query)
ret_list.extend(doctor_hospital_equal_query)
ret_list.extend(get_tag_wiki_data)
ret_list.extend(get_doctor_hospital_data)
......@@ -172,7 +186,7 @@ def get_suggest_tips(query, lat, lng, offset=0, size=50):
QUERY_KEY = "query:search_tip"
query_base64 = base64.b64encode(query.encode('utf8')).decode('utf8')
if redis_client.hget(QUERY_KEY, query_base64) is not None:
value_data = json.loads(str(redis_client.hget(QUERY_KEY, query_base64),encoding='utf-8'))
value_data = json.loads(str(redis_client.hget(QUERY_KEY, query_base64), encoding='utf-8'))
if len(value_data) > 0:
for i in value_data:
......@@ -192,13 +206,49 @@ def get_suggest_tips(query, lat, lng, offset=0, size=50):
"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})
ret_list.extend(query_ret_list)
ret_list.extend(wordresemble_ret_list)
###高亮调整
query_ret_list.extend(wordresemble_ret_list)
for ret in query_ret_list:
query2 = ret["ori_name"]
for item in range(0, len(query)):
is_find = query2.find(query[item])
high_query = None
if is_find >= 0:
highlight_marks = u'<ems>%s</ems>' % query[item]
high_query = query2.replace(query[item], highlight_marks)
query2 = high_query
if high_query == None:
ret["highlight_name"] = query2
else:
ret["highlight_name"] = high_query
###繁体字删掉,把搜索结果加到简体字上边
fanti_query = [{'痩脸针': "瘦脸针"}]
for item in ret_list:
result_num = [[item['results_num'], list(ret.values())[0], list(ret.keys())[0]] for ret in fanti_query
if
list(ret.keys())[0] == item['ori_name']]
if len(result_num) > 0:
ret_list.remove(item)
for item in ret_list:
if item['ori_name'] == result_num[0][1]:
item['results_num'] += result_num[0][0]
####
if len(ret_list) >= 50:
return ret_list[0:50]
else:
......
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