Commit e471fd19 by 黄静

hj

parent 7f816745
......@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# @Time : 2020-05-16 17:30
# @Author : hj
# @File : zhengce-select_es_result.py
# @File : select_es_result.py
# @Software: PyCharm
......@@ -26,8 +26,17 @@ class HX:
self.espassword = "adminGSBes."
self.es = Elasticsearch([self.esip], http_auth=(self.esuser, self.espassword), port=self.esport)
def hxsearch(self,re_item):
def hxsearch(self,re_item,pagesize,currentpage):
print('re_item',re_item)
if currentpage:
start = (currentpage - 1) * pagesize
else:
start = 0
if pagesize:
size = pagesize
else:
size = 4
if re_item == []:
querybody = {
"query": {
......@@ -39,7 +48,8 @@ class HX:
]
}
},
"size": 2000
"from": start,
"size": size
}
else:
querybody = {
......@@ -49,7 +59,8 @@ class HX:
]
}
},
"size": 2000,
"from": start,
"size": size
}
if "qiyeguimo" in re_item:
dsl = {
......@@ -225,12 +236,17 @@ class HX:
print('查询语法:', querybody)
searched = self.es.search(index=self.index_name, doc_type=self.index_type, body=querybody)
es_company_info = {}
company_hx_list = []
if (searched["hits"]["total"] > 0):
for row in searched["hits"]["hits"]:
company_name = row['_source']["companyname"]
company_hx_list.append(company_name)
return company_hx_list
total = searched["hits"]["total"]
es_company_info['company_hx_list'] = company_hx_list
es_company_info['total'] = total
return es_company_info
def select_url(self,company_name):
hx_logo_address = '暂无logo'
......@@ -276,30 +292,36 @@ def hx_company_list(server):
def hx_select_main():
if request.method == 'POST':
requestdata = request.json
print('requestdata',requestdata)
total = ""
select_filter = requestdata.get('select_filter')
pagesize = requestdata.get('pagesize')
currentpage = requestdata.get('currentpage')
try:
base_result_list = []
print(requestdata, 1121212)
re_item = {}
if requestdata != []:
for item in requestdata:
for item in select_filter:
name = item['name']
list = item['list']
re_item[name] = list
company_hx_list = hx.hxsearch(re_item)
for company_name in company_hx_list:
es_company_info = hx.hxsearch(re_item,pagesize,currentpage)
for company_name in es_company_info['company_hx_list']:
base_result = companybase.companyinfo(company_name)
logo_url = hx.select_url(company_name)
base_result['logo'] = logo_url
base_result_list.append(base_result)
total = es_company_info['total']
print("len_result",len(base_result_list))
else:
company_hx_list = hx.hxsearch(requestdata)
for company_name in company_hx_list:
es_company_info = hx.hxsearch(select_filter,pagesize,currentpage)
for company_name in es_company_info['company_hx_list']:
base_result = companybase.companyinfo(company_name)
logo_url = hx.select_url(company_name)
base_result['logo'] = logo_url
base_result_list.append(base_result)
total = es_company_info['total']
print("len_result", len(base_result_list))
except:
base_result_list = "暂无该检索信息,请您修改条件进行检索!"
return {"status": 200, "msg": "成功", "data": base_result_list}
return {"status": 200, "msg": "成功", "data": base_result_list,"total":total}
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