idiom搜索逻辑修复
This commit is contained in:
parent
9d46299f8f
commit
ba11bc3913
|
|
@ -268,7 +268,7 @@ async def search_idiom_list(
|
||||||
)
|
)
|
||||||
tasks.append(
|
tasks.append(
|
||||||
service.suggest_proverb(
|
service.suggest_proverb(
|
||||||
query=query,
|
query=all_in_kana(query),
|
||||||
lang="jp",
|
lang="jp",
|
||||||
model=IdiomJp,
|
model=IdiomJp,
|
||||||
search_field="search_text",
|
search_field="search_text",
|
||||||
|
|
@ -294,7 +294,6 @@ async def search_idiom_list(
|
||||||
query=query,
|
query=query,
|
||||||
lang="zh",
|
lang="zh",
|
||||||
model=IdiomJp,
|
model=IdiomJp,
|
||||||
search_field="search_text",
|
|
||||||
target_field="text",
|
target_field="text",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
@ -308,6 +307,14 @@ async def search_idiom_list(
|
||||||
search_field="text",
|
search_field="text",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
tasks.append(
|
||||||
|
service.suggest_proverb(
|
||||||
|
query=all_in_kana(mapping_query),
|
||||||
|
lang="jp",
|
||||||
|
model=IdiomJp,
|
||||||
|
search_field="search_text",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# --- 3️⃣ 其他语言(默认回退) ---
|
# --- 3️⃣ 其他语言(默认回退) ---
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -92,9 +92,8 @@ async def suggest_proverb(
|
||||||
|
|
||||||
# ✅ 搜索条件:中文时双字段联合匹配
|
# ✅ 搜索条件:中文时双字段联合匹配
|
||||||
if lang == "zh":
|
if lang == "zh":
|
||||||
start_condition = Q(**{f"{chi_exp_field}__istartswith": keyword}) | Q(
|
start_condition = Q(**{f"{chi_exp_field}__istartswith": keyword})
|
||||||
**{f"{search_field}__istartswith": keyword})
|
contain_condition = Q(**{f"{chi_exp_field}__icontains": keyword})
|
||||||
contain_condition = Q(**{f"{chi_exp_field}__icontains": keyword}) | Q(**{f"{search_field}__icontains": keyword})
|
|
||||||
else:
|
else:
|
||||||
start_condition = Q(**{f"{search_field}__istartswith": keyword})
|
start_condition = Q(**{f"{search_field}__istartswith": keyword})
|
||||||
contain_condition = Q(**{f"{search_field}__icontains": keyword})
|
contain_condition = Q(**{f"{search_field}__icontains": keyword})
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import json
|
|
||||||
import random
|
import random
|
||||||
from typing import Tuple, Dict
|
from typing import Tuple, Dict
|
||||||
|
|
||||||
|
|
@ -79,7 +78,7 @@ async def baidu_translation(query: str, from_lang: str, to_lang: str):
|
||||||
raise HTTPException(status_code=500, detail=response.json())
|
raise HTTPException(status_code=500, detail=response.json())
|
||||||
|
|
||||||
data = response.json()
|
data = response.json()
|
||||||
print(json.dumps(data, indent=2, ensure_ascii=False))
|
# print(json.dumps(data, indent=2, ensure_ascii=False))
|
||||||
|
|
||||||
if "trans_result" not in data:
|
if "trans_result" not in data:
|
||||||
raise HTTPException(status_code=500, detail={"error_code": data.get("error_code"), "error_msg": data.get("error_msg")})
|
raise HTTPException(status_code=500, detail={"error_code": data.get("error_code"), "error_msg": data.get("error_msg")})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue