fix: 修复编码查询匹配失效
This commit is contained in:
parent
ec7f383c43
commit
25103727a0
16
api/code.py
16
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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user