Commit f0577ce4a5c7826dcba49543bc9f19446b1aa174
1 parent
d3a4e259
fix last up
Showing
3 changed files
with
6 additions
and
9 deletions
Show diff stats
api/models.py
| ... | ... | @@ -198,7 +198,7 @@ class ProductResult(BaseModel): |
| 198 | 198 | image_url: Optional[str] = Field(None, description="主图URL") |
| 199 | 199 | in_stock: bool = Field(True, description="是否有库存") |
| 200 | 200 | variants: List[VariantResult] = Field(default_factory=list, description="变体列表") |
| 201 | - relevance_score: float = Field(..., ge=0.0, le=1.0, description="相关性分数(0-1)") | |
| 201 | + relevance_score: float = Field(..., ge=0.0, description="相关性分数(ES原始分数)") | |
| 202 | 202 | |
| 203 | 203 | |
| 204 | 204 | class SearchResponse(BaseModel): | ... | ... |
api/result_formatter.py
| ... | ... | @@ -19,7 +19,7 @@ class ResultFormatter: |
| 19 | 19 | |
| 20 | 20 | Args: |
| 21 | 21 | es_hits: List of ES hit dictionaries (with _id, _score, _source) |
| 22 | - max_score: Maximum score for normalization | |
| 22 | + max_score: Maximum score (unused, kept for compatibility) | |
| 23 | 23 | |
| 24 | 24 | Returns: |
| 25 | 25 | List of ProductResult objects |
| ... | ... | @@ -30,11 +30,8 @@ class ResultFormatter: |
| 30 | 30 | source = hit.get('_source', {}) |
| 31 | 31 | score = hit.get('_score', 0.0) |
| 32 | 32 | |
| 33 | - # Normalize relevance score to 0-1 | |
| 34 | - if max_score > 0: | |
| 35 | - relevance_score = min(score / max_score, 1.0) | |
| 36 | - else: | |
| 37 | - relevance_score = 0.0 | |
| 33 | + # Use original ES score directly (no normalization) | |
| 34 | + relevance_score = score | |
| 38 | 35 | |
| 39 | 36 | # Extract variants |
| 40 | 37 | variants = [] | ... | ... |
docs/BASE_CONFIG_GUIDE.md
| ... | ... | @@ -179,7 +179,7 @@ Content-Type: application/json |
| 179 | 179 | 2. **结构化结果**:每个结果包含`product_id`, `title`, `variants`, `relevance_score`等字段 |
| 180 | 180 | 3. **无ES内部字段**:不包含`_id`, `_score`, `_source`等ES内部字段 |
| 181 | 181 | 4. **嵌套variants**:每个商品包含variants数组,每个variant包含完整的变体信息 |
| 182 | -5. **相关性分数**:`relevance_score`是0-1之间的归一化分数 | |
| 182 | +5. **相关性分数**:`relevance_score`是ES原始分数(不进行归一化) | |
| 183 | 183 | |
| 184 | 184 | #### ProductResult字段 |
| 185 | 185 | |
| ... | ... | @@ -196,7 +196,7 @@ Content-Type: application/json |
| 196 | 196 | - `image_url` - 主图URL |
| 197 | 197 | - `in_stock` - 是否有库存 |
| 198 | 198 | - `variants` - 变体列表 |
| 199 | -- `relevance_score` - 相关性分数(0-1) | |
| 199 | +- `relevance_score` - 相关性分数(ES原始分数) | |
| 200 | 200 | |
| 201 | 201 | #### VariantResult字段 |
| 202 | 202 | ... | ... |