Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search: fix handling of underscores and add contains match for names #3514

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion escalation/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var searchTemplate = template.Must(template.New("search").Funcs(search.Helpers()
AND NOT pol.id = any(:omit)
{{end}}
{{if .Search}}
AND ({{orderedPrefixSearch "search" "pol.name"}} OR {{contains "search" "pol.description"}})
AND ({{orderedPrefixSearch "search" "pol.name"}} OR {{contains "search" "pol.description"}} OR {{contains "search" "pol.name"}})
{{end}}
{{if .After.Name}}
AND
Expand Down
4 changes: 2 additions & 2 deletions notification/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ var searchTemplate = template.Must(template.New("search").Funcs(search.Helpers()
{{end}}
{{if .Search}}
AND (
{{orderedPrefixSearch "search" "u.name"}}
{{orderedPrefixSearch "search" "u.name"}} OR {{contains "search" "u.name"}}
OR
{{orderedPrefixSearch "search" "s.name"}}
{{orderedPrefixSearch "search" "s.name"}} OR {{contains "search" "s.name"}}
OR
cm.value ILIKE '%' || :search || '%'
OR
Expand Down
2 changes: 1 addition & 1 deletion schedule/rotation/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var searchTemplate = template.Must(template.New("search").Funcs(search.Helpers()
AND NOT rot.id = any(:omit)
{{end}}
{{if .Search}}
AND ({{orderedPrefixSearch "search" "rot.name"}} OR {{contains "search" "rot.description"}})
AND ({{orderedPrefixSearch "search" "rot.name"}} OR {{contains "search" "rot.description"}} OR {{contains "search" "rot.name"}})
{{end}}
{{if .After.Name}}
AND
Expand Down
2 changes: 1 addition & 1 deletion schedule/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var searchTemplate = template.Must(template.New("search").Funcs(search.Helpers()
AND NOT sched.id = any(:omit)
{{end}}
{{if .Search}}
AND ({{orderedPrefixSearch "search" "sched.name"}} OR {{contains "search" "sched.description"}})
AND ({{orderedPrefixSearch "search" "sched.name"}} OR {{contains "search" "sched.description"}} OR {{contains "search" "sched.name"}})
{{end}}
{{if .After.Name}}
AND
Expand Down
2 changes: 1 addition & 1 deletion search/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type RenderData interface {
func Helpers() template.FuncMap {
return template.FuncMap{
"orderedPrefixSearch": func(argName string, columnName string) string {
return fmt.Sprintf("lower(%s) ~ :~%s", columnName, argName)
return fmt.Sprintf("lower(REPLACE(REPLACE(%s, '_', ' '), '-', ' ')) ~ :~%s", columnName, argName)
},
"contains": func(argName string, columnName string) string {
// search for the term in the column
Expand Down
2 changes: 1 addition & 1 deletion service/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var searchTemplate = template.Must(template.New("search").Funcs(search.Helpers()
)
{{end}}
{{- if and .Search (not .LabelKey) (not .IntegrationKey)}}
AND ({{orderedPrefixSearch "search" "svc.name"}} OR {{contains "search" "svc.description"}})
AND ({{orderedPrefixSearch "search" "svc.name"}} OR {{contains "search" "svc.description"}} OR {{contains "search" "svc.name"}})
{{- end}}
{{- if .After.Name}}
AND
Expand Down
2 changes: 1 addition & 1 deletion user/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var searchTemplate = template.Must(template.New("search").Funcs(search.Helpers()
AND not usr.id = any(:omit)
{{end}}
{{if .Search}}
AND {{orderedPrefixSearch "search" "usr.name"}}
AND ({{orderedPrefixSearch "search" "usr.name"}} OR {{contains "search" "usr.name"}})
{{end}}
{{if .After.Name}}
AND {{if not .FavoritesFirst}}
Expand Down