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

add partial search for description #3195

Merged
merged 4 commits into from
Oct 13, 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"}}
AND ({{orderedPrefixSearch "search" "pol.name"}} OR {{contains "search" "pol.description"}})
{{end}}
{{if .After.Name}}
AND
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"}}
AND ({{orderedPrefixSearch "search" "rot.name"}} OR {{contains "search" "rot.description"}})
{{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"}}
AND ({{orderedPrefixSearch "search" "sched.name"}} OR {{contains "search" "sched.description"}})
{{end}}
{{if .After.Name}}
AND
Expand Down
8 changes: 8 additions & 0 deletions search/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ func Helpers() template.FuncMap {
"orderedPrefixSearch": func(argName string, columnName string) string {
return fmt.Sprintf("lower(%s) ~ :~%s", columnName, argName)
},
"contains": func(argName string, columnName string) string {
// search for the term in the column
//
// - case insensitive
// - allow for partial matches
// - escape % and _ using `\` (backslash -- the default escape character)
return fmt.Sprintf(`%s ilike '%%' || REPLACE(REPLACE(REPLACE(:%s, '\', '\\'), '%%', '\%%'), '_', '\_') || '%%'`, columnName, argName)
},
"textSearch": func(argName string, columnNames ...string) string {
var buf strings.Builder
buf.WriteRune('(')
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"}}
AND ({{orderedPrefixSearch "search" "svc.name"}} OR {{contains "search" "svc.description"}})
{{- end}}
{{- if .After.Name}}
AND
Expand Down