bd96cead
tangwang
1. 动态多语言字段与统一策略配置
|
1
|
"""Configuration helper functions for dynamic multi-language search fields."""
|
9f96d6f3
tangwang
短query不用语义搜索
|
2
3
4
5
6
|
from typing import Dict, List
from .config_loader import SearchConfig
|
bd96cead
tangwang
1. 动态多语言字段与统一策略配置
|
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
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不用语义搜索
|
24
25
|
def get_match_fields_for_index(config: SearchConfig, index_name: str = "default") -> List[str]:
"""
|
bd96cead
tangwang
1. 动态多语言字段与统一策略配置
|
26
27
28
29
|
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不用语义搜索
|
30
|
"""
|
bd96cead
tangwang
1. 动态多语言字段与统一策略配置
|
31
32
33
34
35
36
37
38
39
40
41
|
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不用语义搜索
|
42
43
44
45
46
|
return match_fields
def get_domain_fields(config: SearchConfig) -> Dict[str, List[str]]:
"""
|
bd96cead
tangwang
1. 动态多语言字段与统一策略配置
|
47
48
|
Get dynamic domain fields for compatibility with old diagnostics endpoints.
|
9f96d6f3
tangwang
短query不用语义搜索
|
49
|
Returns:
|
bd96cead
tangwang
1. 动态多语言字段与统一策略配置
|
50
|
A single `default` domain entry generated from dynamic search_fields.
|
9f96d6f3
tangwang
短query不用语义搜索
|
51
|
"""
|
bd96cead
tangwang
1. 动态多语言字段与统一策略配置
|
52
|
return {"default": get_match_fields_for_index(config)}
|