diff --git a/internal/app/ui/routes.go b/internal/app/ui/routes.go index 0ca1ad4..de5ebf8 100644 --- a/internal/app/ui/routes.go +++ b/internal/app/ui/routes.go @@ -211,6 +211,9 @@ func (s *Service) getNodes(c echo.Context) error { var nodes *chef.NodeList var err error if query != "" { + if !strings.Contains(query, ":") { + query = fuzzifySearchStr(query) + } nodes, err = s.chef.SearchNodes(c.Request().Context(), query) } else { nodes, err = s.chef.GetNodes(c.Request().Context()) @@ -230,6 +233,27 @@ func (s *Service) getNodes(c echo.Context) error { }) } +// fuzzifySearchStr mimics the fuzzy search functionality +// provided by chef https://github.com/chef/chef/blob/main/lib/chef/search/query.rb#L109 +func fuzzifySearchStr(s string) string { + format := []string{ + "tags:*%v*", + "roles:*%v*", + "fqdn:*%v*", + "addresses:*%v*", + "policy_name:*%v*", + "policy_group:*%v*", + } + var b strings.Builder + for i, f := range format { + if i > 0 { + b.WriteString(" OR ") + } + b.WriteString(fmt.Sprintf(f, s)) + } + return b.String() +} + func (s *Service) getRoles(c echo.Context) error { roles, err := s.chef.GetRoles(c.Request().Context()) if err != nil {