From 42876ca61cc698f01a37b3e337da88501cd658cb Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Thu, 30 Jul 2026 00:30:38 +0200 Subject: [PATCH] refactor(search): let getFirstValue try multiple metadata keys --- services/search/pkg/content/extractor.go | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/services/search/pkg/content/extractor.go b/services/search/pkg/content/extractor.go index 3d4e457288..a76548ffe3 100644 --- a/services/search/pkg/content/extractor.go +++ b/services/search/pkg/content/extractor.go @@ -2,7 +2,6 @@ package content import ( "context" - "errors" "fmt" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" @@ -13,19 +12,13 @@ type Extractor interface { Extract(ctx context.Context, ri *provider.ResourceInfo) (Document, error) } -func getFirstValue(m map[string][]string, key string) (string, error) { - if m == nil { - return "", errors.New("undefined map") +// getFirstValue returns the first metadata value present among keys, trying them +// in order. It errors when the map is nil or none of the keys holds a value. +func getFirstValue(m map[string][]string, keys ...string) (string, error) { + for _, key := range keys { + if v, ok := m[key]; ok && len(v) > 0 { + return v[0], nil + } } - - v, ok := m[key] - if !ok { - return "", fmt.Errorf("unknown key: %v", key) - } - - if len(v) == 0 { - return "", fmt.Errorf("no values for: %v", key) - } - - return v[0], nil + return "", fmt.Errorf("no value for keys: %v", keys) }