Commit 2131d6ec authored by lixiaofang's avatar lixiaofang

add

parent 3b6b6fbb
......@@ -19,7 +19,7 @@ def get_suggest_tips(query, lat, lng, offset=0, size=50):
try:
have_read_tips_set, ret_list, result_dict = get_query_by_es(query=str(query).lower(), lat=lat, lng=lng,
offset=offset,
size=size)
size=size, highlight_query=query)
if len(ret_list) >= 50:
return ret_list
......@@ -84,9 +84,10 @@ def get_suggest_tips(query, lat, lng, offset=0, size=50):
str_query = ''
for item in ss:
str_query += str(item)
have_read_tips_set, ret_list, result_dict = get_query_by_es(query=str_query, lat=lat, lng=lng,
offset=offset,
size=size)
size=size, highlight_query=query)
logging.info("get ret_list:%s" % ret_list)
return ret_list
......@@ -103,26 +104,19 @@ def set_highlihgt(query=None, ori_name=None):
query2 = ori_name
for item in range(0, len(query)):
all_word.add(query[item])
for item in all_word:
is_find = query2.find(item)
high_query = None
if is_find >= 0:
highlight_marks = u'<>%s</>' % item
high_query = query2.replace(item, highlight_marks)
query2 = high_query
if high_query == None:
highlight_name = query2
else:
highlight_name = high_query
highlight_name = query2.replace('<>', '<ems>').replace('</>', '</ems>')
highlight_name = query2.replace('<>', '<ems>').replace('</>', '</ems>')
return highlight_name
def get_query_by_es(query='', lat=0, lng=0, size=0, offset=0):
def get_query_by_es(query='', lat=0, lng=0, size=0, offset=0, highlight_query=None):
try:
query = query.replace("\u2006", '')
......@@ -158,12 +152,14 @@ def get_query_by_es(query='', lat=0, lng=0, size=0, offset=0):
for tips_item in result_dict["suggest"]["tips-suggest"]:
for hit_item in tips_item["options"]:
logging.info("get hit_item:%s" % hit_item)
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)
hit_item["_source"]["highlight_name"] = set_highlihgt(query, hit_item["_source"]["ori_name"])
hit_item["_source"]["highlight_name"] = set_highlihgt(highlight_query,
hit_item["_source"]["ori_name"])
if hit_item["_source"]["type_flag"] == "hospital":
if lat is not None and lng is not None and lat != 0.0 and lng != 0.0:
if hit_item["_source"]["ori_name"] in g_hospital_pos_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