From 8ac1b47f0fe91b417f2cf811c63cf4158cba03f1 Mon Sep 17 00:00:00 2001 From: Code by Ben Date: Sun, 8 Dec 2024 11:10:40 +1100 Subject: [PATCH] tweaked the search for releaser text for clarity. if searching for 4 or less chars, an initalism lookup is done; if no results are found, a r.Similar search is executed. --- handler/app/context.go | 2 ++ handler/htmx/htmx.go | 17 ++++++++++------- view/app/searchhtmx.tmpl | 2 ++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/handler/app/context.go b/handler/app/context.go index 715a56ac..6b6c8e5c 100644 --- a/handler/app/context.go +++ b/handler/app/context.go @@ -1449,6 +1449,8 @@ func SearchReleaser(c echo.Context) error { data["logo"] = title data["title"] = title data["info"] = "search for a group, initialism, magazine, board, or site" + data["helpText"] = "searching for 4 or fewer characters triggers an initialism lookup, " + + "if no results are found, a new search is made for the releaser names" data["hxPost"] = "/search/releaser" data["inputPlaceholder"] = "Type to search for a releaser…" err := c.Render(http.StatusOK, name, data) diff --git a/handler/htmx/htmx.go b/handler/htmx/htmx.go index 55a660a0..3bd38ff0 100644 --- a/handler/htmx/htmx.go +++ b/handler/htmx/htmx.go @@ -547,7 +547,7 @@ func SearchReleaser(c echo.Context, db *sql.DB, logger *zap.SugaredLogger) error } lookup = append(lookup, slug) var r model.Releasers - if len(slug) < initalism { + if len(slug) <= initalism { if err := r.Initialism(ctx, db, maxResults, lookup...); err != nil { if logger != nil { logger.Error(err) @@ -555,15 +555,18 @@ func SearchReleaser(c echo.Context, db *sql.DB, logger *zap.SugaredLogger) error return c.String(http.StatusServiceUnavailable, "the search query failed") } - } else if err := r.Similar(ctx, db, maxResults, lookup...); err != nil { - if logger != nil { - logger.Error(err) + } + if len(r) == 0 { + if err := r.Similar(ctx, db, maxResults, lookup...); err != nil { + if logger != nil { + logger.Error(err) + } + return c.String(http.StatusServiceUnavailable, + "the search query failed") } - return c.String(http.StatusServiceUnavailable, - "the search query failed") } if len(r) == 0 { - return c.HTML(http.StatusOK, "No releasers found.") + return c.HTML(http.StatusOK, "No initialisms or releasers found.") } err := c.Render(http.StatusOK, "searchreleasers", map[string]interface{}{ "maximum": maxResults, diff --git a/view/app/searchhtmx.tmpl b/view/app/searchhtmx.tmpl index 46f7e4c7..8a211927 100644 --- a/view/app/searchhtmx.tmpl +++ b/view/app/searchhtmx.tmpl @@ -4,6 +4,7 @@ {{- define "content" }} {{- $hxpost := index . "hxPost" }} {{- $placeholder := index . "inputPlaceholder" }} +{{- $helper := index . "helpText"}}
@@ -13,6 +14,7 @@ {{index . "info"}}

+ {{- if ne "" $helper}}{{index . "helpText"}}{{end}}