fix(podcasts): page search hits episode titles/descriptions (issue #8)

WHY: the /podcasts search box filtered feed CARDS only (title, display
name, host, publisher, feed description). D14's episode search existed
only as the /api/podcasts/search endpoint and was never wired into the
page — searching 'Quarter' (present only in episode titles) cleared the
grid while 'Trader' (feed metadata) survived.

The page query now consults SearchMyPodcastEpisodes (subscription-scoped
via RLS — the caller's identity) when a query is present; a feed
surfaces when its OWN metadata OR any of its episodes matches, with an
'N matching episode(s)' badge on the card.

PIN: SSR test with a needle that exists only in an episode title — the
feed must surface with the match count.
This commit is contained in:
John O'Keefe committed 2026-10-29 19:49:39 -04:00
1 parent c753780817
commit ffc80f7ba7
5 files changed
+129 -38

No files matched your search

+22 -1
View File
@@ -168,11 +168,27 @@ func buildPodcastsPageData(c *echo.Context, cfg *Config) (*templates.PodcastsPag
host := c.QueryParam("host")
tag := c.QueryParam("tag")
lang := c.QueryParam("language")
// Episode-level matches (issue #8 / D14): a query also hits episode
// titles + descriptions — the feed surfaces with a match count.
// SearchMyPodcastEpisodes is subscription-scoped via RLS (the
// caller's identity). Only consult it when a query is present.
matchesByFeed := make(map[string]int)
if q != "" {
if eps, err := cfg.Queries.SearchMyPodcastEpisodes(ctx, q); err == nil {
for i := range eps {
key := uuid.UUID(eps[i].SourceFeedID.Bytes).String()
matchesByFeed[key]++
}
}
}
filtered := data.Feeds[:0:0]
for _, f := range data.Feeds {
if q != "" {
hay := strings.ToLower(f.Title + " " + f.DisplayName + " " + f.Host + " " + f.Publisher + " " + f.Description)
if !strings.Contains(hay, q) {
matched := matchesByFeed[f.ID]
if !strings.Contains(hay, q) && matched == 0 {
continue
}
}
@@ -196,6 +212,11 @@ func buildPodcastsPageData(c *echo.Context, cfg *Config) (*templates.PodcastsPag
}
filtered = append(filtered, f)
}
if q != "" {
for i := range filtered {
filtered[i].EpisodeMatches = matchesByFeed[filtered[i].ID]
}
}
data.Feeds = filtered
data.Query = q
data.ContinueFeeds = templates.PodcastContinueFeeds(data.Feeds)