be52af70
tangwang
first commit
|
1
|
"""
|
86d8358b
tangwang
config optimize
|
2
|
Compatibility wrapper for search-behavior config access.
|
be52af70
tangwang
first commit
|
3
|
|
86d8358b
tangwang
config optimize
|
4
5
6
|
The unified loader lives in :mod:`config.loader`. This module now exposes the
search subtree only, so existing search/indexer code can consume a single
source-of-truth search config without reparsing YAML separately.
|
be52af70
tangwang
first commit
|
7
8
|
"""
|
86d8358b
tangwang
config optimize
|
9
|
from __future__ import annotations
|
be52af70
tangwang
first commit
|
10
|
|
86d8358b
tangwang
config optimize
|
11
12
13
|
from dataclasses import asdict
from pathlib import Path
from typing import Any, Dict, List, Optional
|
be52af70
tangwang
first commit
|
14
|
|
86d8358b
tangwang
config optimize
|
15
16
17
18
19
20
21
22
23
|
from config.loader import AppConfigLoader, ConfigurationError
from config.schema import (
FunctionScoreConfig,
IndexConfig,
QueryConfig,
RerankConfig,
SPUConfig,
SearchConfig,
)
|
be52af70
tangwang
first commit
|
24
25
26
|
class ConfigLoader:
|
86d8358b
tangwang
config optimize
|
27
|
"""Load the unified app config and return the search subtree."""
|
42e3aea6
tangwang
tidy
|
28
|
|
86d8358b
tangwang
config optimize
|
29
30
|
def __init__(self, config_file: Optional[Path] = None) -> None:
self._loader = AppConfigLoader(config_file=Path(config_file) if config_file is not None else None)
|
a73a751f
tangwang
enrich
|
31
|
|
86d8358b
tangwang
config optimize
|
32
33
|
def load_config(self, validate: bool = True) -> SearchConfig:
return self._loader.load(validate=validate).search
|
a73a751f
tangwang
enrich
|
34
|
|
9cb7528e
tangwang
店匠体系数据的搜索:mock da...
|
35
|
def validate_config(self, config: SearchConfig) -> List[str]:
|
86d8358b
tangwang
config optimize
|
36
|
errors: List[str] = []
|
33839b37
tangwang
属性值参与搜索:
|
37
38
|
if not config.es_index_name:
errors.append("es_index_name is required")
|
33839b37
tangwang
属性值参与搜索:
|
39
40
|
if not config.field_boosts:
errors.append("field_boosts is empty")
|
33839b37
tangwang
属性值参与搜索:
|
41
|
if config.query_config.default_language not in config.query_config.supported_languages:
|
86d8358b
tangwang
config optimize
|
42
43
44
|
errors.append("default_language must be included in supported_languages")
if config.spu_config.enabled and not config.spu_config.spu_field:
errors.append("spu_field is required when SPU is enabled")
|
be52af70
tangwang
first commit
|
45
|
return errors
|
86d8358b
tangwang
config optimize
|
46
|
|
33839b37
tangwang
属性值参与搜索:
|
47
|
def to_dict(self, config: SearchConfig) -> Dict[str, Any]:
|
86d8358b
tangwang
config optimize
|
48
|
return asdict(config)
|