From a39f7b440dc4ee407475d009f1e28402fe38b040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Tue, 23 May 2023 15:25:16 +0200 Subject: [PATCH] Make field base search case insensitive Fixes part of #6366 --- services/search/pkg/engine/bleve.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/services/search/pkg/engine/bleve.go b/services/search/pkg/engine/bleve.go index e330f7bb087..828ddd240b1 100644 --- a/services/search/pkg/engine/bleve.go +++ b/services/search/pkg/engine/bleve.go @@ -6,6 +6,7 @@ import ( "math" "path" "path/filepath" + "regexp" "strings" "time" @@ -143,6 +144,7 @@ func (b *Bleve) Search(_ context.Context, sir *searchService.SearchIndexRequest) } bleveReq := bleve.NewSearchRequest(q) + bleveReq.Highlight = bleve.NewHighlight() switch { case sir.PageSize == -1: @@ -364,7 +366,19 @@ func formatQuery(q string) string { cq = strings.ReplaceAll(cq, strings.ToLower(field)+":", field+":") } - if strings.Contains(cq, ":") { + fieldRe := regexp.MustCompile(`\w+:[^ ]+`) + if fieldRe.MatchString(cq) { + parts := strings.Split(cq, " ") + + cq = "" + for _, part := range parts { + fieldParts := strings.SplitN(part, ":", 2) + if len(fieldParts) > 1 { + cq += fieldParts[0] + ":" + strings.ToLower(fieldParts[1]) + " " + } else { + cq += part + } + } return cq // Sophisticated field based search }