Commit 9e5b00f8 authored by 段英荣's avatar 段英荣

Merge branch 'dev' into 'test'

Dev

See merge request !9
parents 02d3ce94 80561432
......@@ -22,8 +22,8 @@ class ESPerform(object):
def get_cli(cls,es_ip_list=None):
try:
es_info_list = es_ip_list if es_ip_list else cls.cli_info_list
if es_ip_list:#tricky的做法,兼容测试es
cls.index_prefix = "gm_test"
# if es_ip_list:#tricky的做法,兼容测试es
# cls.index_prefix = "gm_test"
cls.cli_obj = Elasticsearch(es_info_list)
return cls.cli_obj
......
......@@ -33,39 +33,42 @@ def get_suggest_tips(query,lat,lng,offset=0,size=50):
}
},
"_source": {
"include": ["id", "ori_name", "offline_score", "is_online","type_flag","results_num"]
"includes": ["id", "ori_name", "offline_score", "is_online","type_flag","results_num"]
}
}
have_read_tips_set = set()
ret_list = 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)
for tips_item in result_dict["suggest"]["tips-suggest"]:
for hit_item in tips_item["options"]:
highlight_marks = u'<ems>%s</ems>' % query
hit_item["_source"]["highlight_name"] = hit_item["_source"]["ori_name"].replace(query,highlight_marks)
if hit_item["_source"]["ori_name"] not in have_read_tips_set:
have_read_tips_set.add(hit_item["_source"]["ori_name"])
highlight_marks = u'<ems>%s</ems>' % query
hit_item["_source"]["highlight_name"] = hit_item["_source"]["ori_name"].replace(query,highlight_marks)
if hit_item["_source"]["type_flag"] == "hospital":
if hit_item["_source"]["ori_name"] in g_hospital_pos_dict:
distance = point_distance(lng,lat,g_hospital_pos_dict[hit_item["_source"]["ori_name"]][0],g_hospital_pos_dict[hit_item["_source"]["ori_name"]][1])
if distance < 1000*50:
if distance < 1000:
if distance < 100:
hit_item["_source"]["describe"] = "<100" + "米"
if hit_item["_source"]["type_flag"] == "hospital":
if hit_item["_source"]["ori_name"] in g_hospital_pos_dict:
distance = point_distance(lng,lat,g_hospital_pos_dict[hit_item["_source"]["ori_name"]][0],g_hospital_pos_dict[hit_item["_source"]["ori_name"]][1])
if distance < 1000*50:
if distance < 1000:
if distance < 100:
hit_item["_source"]["describe"] = "<100" + "米"
else:
hit_item["_source"]["describe"] = "约" + str(int(distance)) + "米"
else:
hit_item["_source"]["describe"] = "约" + str(int(distance)) + "米"
hit_item["_source"]["describe"] = "约" + str(round(1.0*distance/1000,1)) + "km"
else:
hit_item["_source"]["describe"] = "约" + str(round(1.0*distance/1000,1)) + "km"
hit_item["_source"]["describe"] = ">50km"
else:
hit_item["_source"]["describe"] = ">50km"
hit_item["_source"]["describe"] = ""
else:
hit_item["_source"]["describe"] = ""
else:
if hit_item["_source"]["type_flag"] == "doctor":
hit_item["_source"]["describe"] = ""
else:
hit_item["_source"]["describe"] = "约"+str(hit_item["_source"]["results_num"])+"个结果" if hit_item["_source"]["results_num"] else ""
ret_list.append(hit_item["_source"])
if hit_item["_source"]["type_flag"] == "doctor":
hit_item["_source"]["describe"] = ""
else:
hit_item["_source"]["describe"] = "约"+str(hit_item["_source"]["results_num"])+"个结果" if hit_item["_source"]["results_num"] else ""
ret_list.append(hit_item["_source"])
return ret_list
except:
......
......@@ -21,8 +21,9 @@ def uuid4():
def get_tips_suggest_list(instance_cn_name):
try:
ch_full_weight = 6.0 * 1000
py_full_weight = 3.0 * 1000
#ch_full_weight = 6.0 * 1000
#py_full_weight = 3.0 * 1000
full_weight = 3.0 * 1000
py_acronym_full_weight = 3.0 * 1000
py_acronym_prefix_weight = 2
......@@ -42,7 +43,7 @@ def get_tips_suggest_list(instance_cn_name):
for i in range(len(ch_full_word)):
ch_name_term = ch_full_word[i:].strip()
if ch_name_term and ch_full_word[i]!="(" and ch_full_word[i]!=")":
prefix_weight = ch_prefix_weight if len(ch_name_term) != len(ch_full_word) else ch_full_weight
prefix_weight = ch_prefix_weight if len(ch_name_term) != len(ch_full_word) else full_weight
suggest_type = 0 if len(ch_name_term) != len(ch_full_word) else 1
term_begin_prefix_weight = begin_prefix_weight if i == 0 else 1.0
suggest_item = {
......@@ -64,8 +65,7 @@ def get_tips_suggest_list(instance_cn_name):
for i in range(len(py_full_word)):
py_name_term = py_full_word[i:].strip()
if py_name_term and py_full_word[i]!="(" and py_full_word[i]!=")":
prefix_weight = py_prefix_weight if len(py_name_term) != len(
py_full_word) else py_full_weight
prefix_weight = py_prefix_weight if len(py_name_term) != len(py_full_word) else full_weight
suggest_type = 2 if len(py_name_term) != len(py_full_word) else 3
term_begin_prefix_weight = begin_prefix_weight if i == 0 else 1.0
suggest_item = {
......
......@@ -24,6 +24,8 @@ from trans2es.utils.tag_transfer import TagTransfer
from trans2es.utils.wordresemble import WordResemble
from libs.es import ESPerform
from libs.tools import tzlc,getMd5Digest
from trans2es.commons.words_utils import QueryWordAttr
from gm_types.gaia import SERVICE_ITEM_PRICE_TYPE, DOCTOR_TYPE
from gm_types.gaia import (
......@@ -155,6 +157,7 @@ class TypeInfo(object):
resemble_dict = copy.deepcopy(suggest_dict)
resemble_dict["id"] = suggest_dict["id"] + "_" + getMd5Digest(resemble_item)
resemble_dict["ori_name"] = resemble_item
resemble_dict["results_num"] = QueryWordAttr.get_query_results_num(resemble_item)
resemble_dict["offline_score"] = 0
resemble_dict["suggest"]["weight"] = 0
data_list.append(resemble_dict)
......
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