From 25103727a0c07d32e3842cfba1835cb9a724d8d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9A=93=E6=9C=88=E5=BD=92=E5=B0=98?= Date: Mon, 17 Feb 2025 19:38:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=8C=B9=E9=85=8D=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/code.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/api/code.py b/api/code.py index b16c7d1..0c22baa 100644 --- a/api/code.py +++ b/api/code.py @@ -255,7 +255,7 @@ async def get_code_list(request: Request, query = { "query": { "match": { - "brief_description": { + "description": { "query": description.strip(), "fuzziness": "AUTO" # 自动模糊匹配 } @@ -275,14 +275,14 @@ async def get_code_list(request: Request, max_score = data["hits"].get("max_score", 1) # 处理每一条匹配结果 for hit in data["hits"]["hits"]: - code = await Code.get_or_none(code=hit["_source"]["hts8"]) + code = await Code.get_or_none(code=str(hit["_source"]["code"])) # 归一化匹配度,转换为百分比 match_rate = round((hit["_score"] / max_score) * 100, 2) # 归一化后计算百分比 # 将匹配结果添加到列表中 matches.append({ "id": code.id if code else None, - "code": hit["_source"]["hts8"], # 获取商品编码 - "description": hit["_source"]["brief_description"], # 获取商品描述 + "code": hit["_source"]["code"], # 获取商品编码 + "description": hit["_source"]["description"], # 获取商品描述 "match_rate": match_rate # 匹配度(百分比) }) query_code = await QueryCode.create( @@ -355,7 +355,7 @@ async def get_code_list(request: Request, query = { "query": { "match": { - "brief_description": { + "description": { "query": row["text"].strip(), "fuzziness": "AUTO" # 自动模糊匹配 } @@ -375,14 +375,14 @@ async def get_code_list(request: Request, max_score = data["hits"].get("max_score", 1) # 处理每一条匹配结果 for hit in data["hits"]["hits"]: - code = await Code.get_or_none(code=hit["_source"]["hts8"]) + code = await Code.get_or_none(code=str(hit["_source"]["code"])) # 归一化匹配度,转换为百分比 match_rate = round((hit["_score"] / max_score) * 100, 2) # 归一化后计算百分比 # 将匹配结果添加到列表中 matches.append({ "id": code.id if code else None, - "code": hit["_source"]["hts8"], # 获取商品编码 - "description": hit["_source"]["brief_description"], # 获取商品描述 + "code": hit["_source"]["code"], # 获取商品编码 + "description": hit["_source"]["description"], # 获取商品描述 "match_rate": match_rate # 匹配度(百分比) }) query_code = await QueryCode.create(