From 66eb5e35cd066b65b846b82d9e0b07a5352c02e6 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Mon, 8 Dec 2025 11:18:33 +0300 Subject: [PATCH] add to document builder --- pkg/storage/unified/resource/document.go | 1 + pkg/storage/unified/search/bleve_mappings.go | 16 +++++++++++++--- .../unified/search/bleve_mappings_test.go | 3 ++- .../builders/testdata/doc/folder-aaa-out.json | 6 +++++- .../search/builders/testdata/doc/folder-aaa.json | 11 ++++++++++- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/pkg/storage/unified/resource/document.go b/pkg/storage/unified/resource/document.go index adc7d14a718..6e08736935a 100644 --- a/pkg/storage/unified/resource/document.go +++ b/pkg/storage/unified/resource/document.go @@ -304,6 +304,7 @@ const SEARCH_FIELD_TITLE_PHRASE = "title_phrase" // filtering/sorting on title b const SEARCH_FIELD_DESCRIPTION = "description" const SEARCH_FIELD_TAGS = "tags" const SEARCH_FIELD_LABELS = "labels" // All labels, not a specific one +const SEARCH_FIELD_OWNER_REFERENCES = "ownerReferences" const SEARCH_FIELD_FOLDER = "folder" const SEARCH_FIELD_CREATED = "created" diff --git a/pkg/storage/unified/search/bleve_mappings.go b/pkg/storage/unified/search/bleve_mappings.go index 43adcbc607e..f1589d088fd 100644 --- a/pkg/storage/unified/search/bleve_mappings.go +++ b/pkg/storage/unified/search/bleve_mappings.go @@ -60,7 +60,7 @@ func getBleveDocMappings(fields resource.SearchableDocumentFields) *mapping.Docu } mapper.AddFieldMappingsAt(resource.SEARCH_FIELD_DESCRIPTION, descriptionMapping) - tagsMapping := &mapping.FieldMapping{ + mapper.AddFieldMappingsAt(resource.SEARCH_FIELD_TAGS, &mapping.FieldMapping{ Name: resource.SEARCH_FIELD_TAGS, Type: "text", Analyzer: keyword.Name, @@ -69,8 +69,18 @@ func getBleveDocMappings(fields resource.SearchableDocumentFields) *mapping.Docu IncludeTermVectors: false, IncludeInAll: true, DocValues: false, - } - mapper.AddFieldMappingsAt(resource.SEARCH_FIELD_TAGS, tagsMapping) + }) + + mapper.AddFieldMappingsAt(resource.SEARCH_FIELD_OWNER_REFERENCES, &mapping.FieldMapping{ + Name: resource.SEARCH_FIELD_OWNER_REFERENCES, + Type: "text", + Analyzer: keyword.Name, + Store: false, + Index: true, + IncludeTermVectors: false, + IncludeInAll: false, + DocValues: false, + }) folderMapping := &mapping.FieldMapping{ Name: resource.SEARCH_FIELD_FOLDER, diff --git a/pkg/storage/unified/search/bleve_mappings_test.go b/pkg/storage/unified/search/bleve_mappings_test.go index 3b8027ee06e..ff0a9315d31 100644 --- a/pkg/storage/unified/search/bleve_mappings_test.go +++ b/pkg/storage/unified/search/bleve_mappings_test.go @@ -36,6 +36,7 @@ func TestDocumentMapping(t *testing.T) { Checksum: "ooo", TimestampMillis: 1234, }, + OwnerReferences: []string{"iam.grafana.app/Team/devops", "iam.grafana.app/User/xyz"}, } data.UpdateCopyFields() @@ -49,5 +50,5 @@ func TestDocumentMapping(t *testing.T) { fmt.Printf("DOC: fields %d\n", len(doc.Fields)) fmt.Printf("DOC: size %d\n", doc.Size()) - require.Equal(t, 17, len(doc.Fields)) + require.Equal(t, 19, len(doc.Fields)) } diff --git a/pkg/storage/unified/search/builders/testdata/doc/folder-aaa-out.json b/pkg/storage/unified/search/builders/testdata/doc/folder-aaa-out.json index f3d12b9a6e8..3303172b2cf 100644 --- a/pkg/storage/unified/search/builders/testdata/doc/folder-aaa-out.json +++ b/pkg/storage/unified/search/builders/testdata/doc/folder-aaa-out.json @@ -16,5 +16,9 @@ "kind": "repo", "id": "MyGIT" }, - "managedBy": "repo:MyGIT" + "managedBy": "repo:MyGIT", + "ownerReferences": [ + "iam.grafana.app/Team/engineering", + "iam.grafana.app/User/test" + ] } \ No newline at end of file diff --git a/pkg/storage/unified/search/builders/testdata/doc/folder-aaa.json b/pkg/storage/unified/search/builders/testdata/doc/folder-aaa.json index 93963ca6397..38a4f7e4e07 100644 --- a/pkg/storage/unified/search/builders/testdata/doc/folder-aaa.json +++ b/pkg/storage/unified/search/builders/testdata/doc/folder-aaa.json @@ -9,7 +9,16 @@ "annotations": { "grafana.app/createdBy": "user:1", "grafana.app/repoName": "MyGIT" - } + }, + "ownerReferences": [{ + "apiVersion": "iam.grafana.app/v1alpha1", + "kind": "Team", + "name": "engineering" + }, { + "apiVersion": "iam.grafana.app/v1alpha1", + "kind": "User", + "name": "test" + }] }, "spec": { "title": "test-aaa"