From a324664cc035782f7c251968c5fb6648931c30b2 Mon Sep 17 00:00:00 2001 From: edy Date: Fri, 7 Aug 2026 17:46:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E7=B4=A2=E5=87=BA=E5=8F=82:=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=B4=A0=E6=9D=90=20cover=5Furl=20=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- app/es/index_mappings.py | 2 ++ app/es/search.py | 1 + app/schemas/search_material.py | 1 + tests/test_retrieval.py | 2 ++ tests/test_search_material_projection.py | 10 ++++++++++ 5 files changed, 16 insertions(+) diff --git a/app/es/index_mappings.py b/app/es/index_mappings.py index 1838625..4e3bbbc 100644 --- a/app/es/index_mappings.py +++ b/app/es/index_mappings.py @@ -51,6 +51,7 @@ def build_somni_audio_materials_mapping(embedding_dim: int) -> dict[str, Any]: "description_vector": f"description_text 的 {embedding_dim} 维 embedding", "status": "是否启用;true 表示可参与检索与同步", "audio_url": "音频文件 CDN / 对象存储 URL", + "cover_url": "封面图 CDN / 对象存储 URL", "operation_type": "0 大模型打标,1 人工打标", "tag_id": "标签 ID,关联 somni_audio_tag_dictionary._id", "code": "标签编码,用于规则判断与接口传输", @@ -98,6 +99,7 @@ def build_somni_audio_materials_mapping(embedding_dim: int) -> dict[str, Any]: ), "status": _field("boolean", "是否启用;true 表示可参与检索与同步"), "audio_url": _field("keyword", "音频文件地址(CDN / 对象存储 / 内部资源 URL)"), + "cover_url": _field("keyword", "封面图地址(CDN / 对象存储 / 内部资源 URL)"), "operation_type": _field( "integer", "标注操作类型:0 大模型打标,1 人工打标", diff --git a/app/es/search.py b/app/es/search.py index cc967a8..14c4325 100644 --- a/app/es/search.py +++ b/app/es/search.py @@ -26,6 +26,7 @@ "audio_name", "description", "audio_url", + "cover_url", "sleep_stage_tags", "content_form_tags", "mechanism_tags", diff --git a/app/schemas/search_material.py b/app/schemas/search_material.py index 8c0ce7f..103046c 100644 --- a/app/schemas/search_material.py +++ b/app/schemas/search_material.py @@ -10,6 +10,7 @@ def project_search_material(doc: dict[str, Any]) -> dict[str, Any]: "audio_name": str(doc.get("audio_name") or ""), "description": str(doc.get("description") or ""), "audio_url": str(doc.get("audio_url") or ""), + "cover_url": str(doc.get("cover_url") or ""), "content_form_tags": _project_content_form_tags(doc.get("content_form_tags")), "audio_engineering_tags": _project_engineering_tags( doc.get("audio_engineering_tags") diff --git a/tests/test_retrieval.py b/tests/test_retrieval.py index bed3c76..77c25ce 100644 --- a/tests/test_retrieval.py +++ b/tests/test_retrieval.py @@ -667,6 +667,7 @@ async def test_search_returns_projected_material() -> None: "audio_name": "雨声A", "description": "描述", "audio_url": doc["audio_url"], + "cover_url": "", "content_form_tags": [{"name": "雨声", "parent_tag_id": "p1"}], "audio_engineering_tags": [], } @@ -706,6 +707,7 @@ async def test_text_query_can_return_description_only_recall() -> None: "audio_name": "描述命中", "description": "海边声音", "audio_url": "https://cdn.example.com/描述命中.mp3", + "cover_url": "", "content_form_tags": [{"name": "海浪", "parent_tag_id": "p2"}], "audio_engineering_tags": [], } diff --git a/tests/test_search_material_projection.py b/tests/test_search_material_projection.py index 3bbbd80..75fbbfb 100644 --- a/tests/test_search_material_projection.py +++ b/tests/test_search_material_projection.py @@ -8,6 +8,7 @@ def test_project_keeps_only_api_fields() -> None: "audio_name": "雨声", "description": "轻柔雨声", "audio_url": "https://cdn/a.mp3", + "cover_url": "https://cdn/a-cover.jpg", "status": True, "sleep_stage_tags": [{"tag_id": "s1", "name": "放松"}], "mechanism_tags": [{"tag_id": "m1", "name": "放松"}], @@ -39,6 +40,7 @@ def test_project_keeps_only_api_fields() -> None: "audio_name": "雨声", "description": "轻柔雨声", "audio_url": "https://cdn/a.mp3", + "cover_url": "https://cdn/a-cover.jpg", "content_form_tags": [{"name": "雨声", "parent_tag_id": "p1"}], "audio_engineering_tags": [ {"code": "event_density", "value": {"code": "low"}} @@ -60,3 +62,11 @@ def test_project_missing_value_is_null() -> None: } ) assert out["audio_engineering_tags"] == [{"code": "tempo", "value": None}] + assert out["cover_url"] == "" + + +def test_project_cover_url_empty_when_absent() -> None: + out = project_search_material( + {"_id": "1", "audio_name": "a", "audio_url": "u"} + ) + assert out["cover_url"] == ""