Skip to content

Commit

Permalink
add partial search for description (#3195)
Browse files Browse the repository at this point in the history
* add partial search for description

* add contains func

* escape contains search

---------

Co-authored-by: Lakshmi V <[email protected]>
Co-authored-by: Nathaniel Caza <[email protected]>
  • Loading branch information
3 people authored Oct 13, 2023
1 parent 3671734 commit 4b95ef8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
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

0 comments on commit 4b95ef8

Please sign in to comment.