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

modify

parent 21db36ed
...@@ -167,7 +167,7 @@ class ESPerform(object): ...@@ -167,7 +167,7 @@ class ESPerform(object):
@classmethod @classmethod
def get_search_results(cls, es_cli,sub_index_name,query_body,offset=0,size=10, def get_search_results(cls, es_cli,sub_index_name,query_body,offset=0,size=10,
auto_create_index=False,doc_type="_doc",aggregations_query=False): auto_create_index=False,doc_type="_doc",aggregations_query=False,is_suggest_request=False):
try: try:
assert (es_cli is not None) assert (es_cli is not None)
...@@ -183,14 +183,17 @@ class ESPerform(object): ...@@ -183,14 +183,17 @@ class ESPerform(object):
logging.info("duan add,query_body:%s" % str(query_body).encode("utf-8")) logging.info("duan add,query_body:%s" % str(query_body).encode("utf-8"))
res = es_cli.search(index=official_index_name,doc_type=doc_type,body=query_body,from_=offset,size=size) res = es_cli.search(index=official_index_name,doc_type=doc_type,body=query_body,from_=offset,size=size)
result_dict = {
"total_count":res["hits"]["total"], if is_suggest_request:
"hits":res["hits"]["hits"] return res
} else:
if aggregations_query: result_dict = {
result_dict["aggregations"] = res["aggregations"] "total_count":res["hits"]["total"],
"hits":res["hits"]["hits"]
return result_dict }
if aggregations_query:
result_dict["aggregations"] = res["aggregations"]
return result_dict
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"total_count":0,"hits":[]} return {"total_count":0,"hits":[]}
\ No newline at end of file
...@@ -76,8 +76,8 @@ def query_tag(query,offset,size): ...@@ -76,8 +76,8 @@ def query_tag(query,offset,size):
ret_list = list() ret_list = list()
result_dict = ESPerform.get_search_results(ESPerform.get_cli(),sub_index_name="tag",query_body=q,offset=offset,size=size) 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 hit_item in result_dict["hits"]: for hit_item in result_dict["suggest"]["tips-suggest"]["options"]:
hit_item["_source"]["highlight"] = u'<ems>%s</ems>' % query hit_item["_source"]["highlight"] = u'<ems>%s</ems>' % query
ret_list.append(hit_item["_source"]) ret_list.append(hit_item["_source"])
......
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