diff --git a/apps/api/src/db/models.py b/apps/api/src/db/models.py index 90a13230..cee42a04 100644 --- a/apps/api/src/db/models.py +++ b/apps/api/src/db/models.py @@ -494,11 +494,11 @@ class KnowledgeEntryRecord(Base): nullable=False, comment="分類樹節點 (基礎設施/應用層/AI系統/安全合規)", ) - tags: Mapped[list[dict[str, Any]]] = mapped_column( + tags: Mapped[list[str]] = mapped_column( JSON, default=list, nullable=False, - comment="標籤列表 (JSONB)", + comment="標籤列表 (JSONB string array)", ) # Source & Status diff --git a/apps/api/src/repositories/knowledge_repository.py b/apps/api/src/repositories/knowledge_repository.py index b6526406..3844ebbf 100644 --- a/apps/api/src/repositories/knowledge_repository.py +++ b/apps/api/src/repositories/knowledge_repository.py @@ -115,6 +115,11 @@ class KnowledgeDBRepository: if status: query = query.where(KnowledgeEntryRecord.status == status) count_query = count_query.where(KnowledgeEntryRecord.status == status) + if tags: + for tag in tags: + tag_filter = KnowledgeEntryRecord.tags.op('@>')(f'["{tag}"]') + query = query.where(tag_filter) + count_query = count_query.where(tag_filter) if q: like_q = f"%{q}%" filter_cond = or_(