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 23, 2023
1 parent 77e86ed commit 8bafbcf
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 8bafbcf

Please sign in to comment.