Commit a0316310 by larosa

match the table and request to es

parent 00da6858
Showing with 33 additions and 2 deletions
...@@ -79,17 +79,34 @@ def main(): ...@@ -79,17 +79,34 @@ def main():
df = pd.read_excel('table.xlsx') df = pd.read_excel('table.xlsx')
data = df.iloc[:, [0]].values data = df.iloc[:, [0]].values
ans = [] ans = []
result = []
for i in range(len(data)): for i in range(len(data)):
if i > 10:
break # for debug, don't forget to delete this line.
sku_name_str = data[i][0] sku_name_str = data[i][0]
res_tmp = match_sku(sku_name_str) res_tmp = match_sku(sku_name_str)
ans.append(res_tmp) ans.append(res_tmp)
for i in range(len(ans)): for i in range(len(ans)):
score_in_one_row = []
for j in range(len(ans[i])): for j in range(len(ans[i])):
tmp_goods_name = ans[i][j] tmp_goods_name = ans[i][j]
tmp_query = query tmp_query = query
tmp_query["query"]["bool"]["must"][0]["match"]["goods_name"] = tmp_goods_name tmp_query["query"]["bool"]["must"][0]["match"]["goods_name"] = tmp_goods_name
tmp_map = process(tmp_query)
if len(tmp_map) != 0:
score_in_one_row.append(tmp_map)
if len(score_in_one_row) == 0:
continue
else:
max_score = score_in_one_row[0].get("score")
index = 0
for k in range(len(score_in_one_row)):
if score_in_one_row[k].get("score") > max_score:
max_score = score_in_one_row[k].get("score")
index = k
result.append(score_in_one_row[index])
return result
def match_sku(s: str) -> []: def match_sku(s: str) -> []:
# s = "RG58/U射频连接线SMA公头转BNC公头延长线 SMA/BNC-JJ Q9/SMA-JJ RG58/U-SMA/BNC-JJ 2m" # s = "RG58/U射频连接线SMA公头转BNC公头延长线 SMA/BNC-JJ Q9/SMA-JJ RG58/U-SMA/BNC-JJ 2m"
...@@ -124,6 +141,19 @@ def post_to_elasticsearch(q: dict): ...@@ -124,6 +141,19 @@ def post_to_elasticsearch(q: dict):
ans = response.json() ans = response.json()
return ans return ans
def process(query_str: dict):
res = post_to_elasticsearch(query_str)
if res["hits"]["max_score"] is not None and res["hits"]["max_score"] > 80:
for i in range(len(res["hits"]["hits"])):
if res["hits"]["hits"][i]["_score"] == res["hits"]["max_score"]:
_score = res["hits"]["hits"][i]["_score"]
_goods_name = res["hits"]["hits"][i]["_source"]["goods_name"]
_goods_id = res["hits"]["hits"][i]["_source"]["goods_id"]
_brand_name = res["hits"]["hits"][i]["_source"]["brand_name"]
return {"goods_name": _goods_name, "goods_id": _goods_id, "brand_name": _brand_name, "score": _score}
return {}
if __name__ == '__main__': if __name__ == '__main__':
main() res = main()
print(res)
\ No newline at end of file
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 sign in to comment