Skip to content

Commit

Permalink
Make field base search case insensitive
Browse files Browse the repository at this point in the history
Fixes part of owncloud#6366
  • Loading branch information
aduffeck committed May 24, 2023
1 parent ae75893 commit 9fe1225
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion services/search/pkg/engine/bleve.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math"
"path"
"path/filepath"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 9fe1225

Please sign in to comment.