bd96cead
tangwang
1. 动态多语言字段与统一策略配置
|
1
|
"""Configuration helper functions for dynamic multi-language search fields."""
|
9f96d6f3
tangwang
短query不用语义搜索
|
2
3
|
from typing import Dict, List
|
86d8358b
tangwang
config optimize
|
4
5
|
from config.schema import SearchConfig
|
9f96d6f3
tangwang
短query不用语义搜索
|
6
7
|
|
bd96cead
tangwang
1. 动态多语言字段与统一策略配置
|
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
def _format_field_with_boost(field_name: str, boost: float) -> str:
if abs(float(boost) - 1.0) < 1e-9:
return field_name
return f"{field_name}^{boost}"
def _get_boost(config: SearchConfig, base_field: str, language: str = "") -> float:
lang = (language or "").strip().lower()
if lang:
lang_key = f"{base_field}.{lang}"
if lang_key in config.field_boosts:
return float(config.field_boosts[lang_key])
if base_field in config.field_boosts:
return float(config.field_boosts[base_field])
return 1.0
|
9f96d6f3
tangwang
短query不用语义搜索
|
25
26
|
def get_match_fields_for_index(config: SearchConfig, index_name: str = "default") -> List[str]:
"""
|
bd96cead
tangwang
1. 动态多语言字段与统一策略配置
|
27
28
29
30
|
Deprecated compatibility wrapper.
`indexes` is no longer used by runtime query building. This function now returns
dynamic match fields for the default language based on query_config.search_fields.
|
9f96d6f3
tangwang
短query不用语义搜索
|
31
|
"""
|
bd96cead
tangwang
1. 动态多语言字段与统一策略配置
|
32
33
34
35
36
37
38
39
40
41
42
|
del index_name
lang = (config.query_config.default_language or "en").strip().lower()
match_fields: List[str] = []
for base_field in config.query_config.multilingual_fields:
field_name = f"{base_field}.{lang}"
match_fields.append(_format_field_with_boost(field_name, _get_boost(config, base_field, lang)))
for shared_field in config.query_config.shared_fields:
match_fields.append(_format_field_with_boost(shared_field, _get_boost(config, shared_field)))
|
9f96d6f3
tangwang
短query不用语义搜索
|
43
44
45
46
47
|
return match_fields
def get_domain_fields(config: SearchConfig) -> Dict[str, List[str]]:
"""
|
bd96cead
tangwang
1. 动态多语言字段与统一策略配置
|
48
49
|
Get dynamic domain fields for compatibility with old diagnostics endpoints.
|
9f96d6f3
tangwang
短query不用语义搜索
|
50
|
Returns:
|
bd96cead
tangwang
1. 动态多语言字段与统一策略配置
|
51
|
A single `default` domain entry generated from dynamic search_fields.
|
9f96d6f3
tangwang
短query不用语义搜索
|
52
|
"""
|
bd96cead
tangwang
1. 动态多语言字段与统一策略配置
|
53
|
return {"default": get_match_fields_for_index(config)}
|