From a781121c3f6491c0468dc40e30d1e46816e5a016 Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Thu, 15 Aug 2024 09:36:13 +0800 Subject: [PATCH] fix: support keylike search (#21031) Co-authored-by: Qiu Jian --- pkg/apis/metadata.go | 3 +++ pkg/cloudcommon/db/metadata.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/pkg/apis/metadata.go b/pkg/apis/metadata.go index ae7c4af188..cfa915e10e 100644 --- a/pkg/apis/metadata.go +++ b/pkg/apis/metadata.go @@ -54,6 +54,9 @@ type MetadataBaseFilterInput struct { // 同时显示用户标签 WithUserMeta *bool `json:"with_user_meta"` + // 按key模糊匹配 + KeyLike string `json:"key_like"` + // 按Key过滤 Key []string `json:"key"` diff --git a/pkg/cloudcommon/db/metadata.go b/pkg/cloudcommon/db/metadata.go index 2e517304c3..f89fc70f33 100644 --- a/pkg/cloudcommon/db/metadata.go +++ b/pkg/cloudcommon/db/metadata.go @@ -341,6 +341,9 @@ func (manager *SMetadataManager) metaDataQuery2List(ctx context.Context, q *sqlc } func (manager *SMetadataManager) metadataBaseFilter(q *sqlchemy.SQuery, input apis.MetadataBaseFilterInput) *sqlchemy.SQuery { + if len(input.KeyLike) > 0 { + q = q.Contains("key", input.KeyLike) + } if len(input.Key) > 0 { q = q.In("key", input.Key) }