Skip to content

Commit

Permalink
tweaked the search for releaser text for clarity.
Browse files Browse the repository at this point in the history
if searching for 4 or less chars, an initalism lookup is done; if no results are found, a r.Similar search is executed.
  • Loading branch information
bengarrett committed Dec 8, 2024
1 parent 71bf47f commit 8ac1b47
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions handler/app/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 10 additions & 7 deletions handler/htmx/htmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,23 +547,26 @@ 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)
}
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,
Expand Down
2 changes: 2 additions & 0 deletions view/app/searchhtmx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{{- define "content" }}
{{- $hxpost := index . "hxPost" }}
{{- $placeholder := index . "inputPlaceholder" }}
{{- $helper := index . "helpText"}}
<div class="row justify-content-md-center">
<div class="col-md-8 col-lg-6">
<div class="card border-dark mb-3">
Expand All @@ -13,6 +14,7 @@
<small class="fs-5 fw-lighter">{{index . "info"}}</small>
</h5>
<p class="card-text">
{{- if ne "" $helper}}<small class="text-muted">{{index . "helpText"}}</small>{{end}}
<div class="input-group">
<div class="input-group-text">
<div id="search-htmx-indicator" class="htmx-indicator spinner-border spinner-border-sm text-secondary" role="status">
Expand Down

0 comments on commit 8ac1b47

Please sign in to comment.