From bf7901ab297b400d889fc796a3414901f109dfec Mon Sep 17 00:00:00 2001 From: xarmian Date: Wed, 15 Apr 2026 12:33:37 -0400 Subject: [PATCH] feat: add facet summary to CLI search output (#128) Show collection breakdown (e.g. "docs: 9, ideas: 8, tasks: 53") after the result count when searching across all collections. Hidden when filtering by a specific collection. --- cmd/pad/main.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cmd/pad/main.go b/cmd/pad/main.go index 90423b55..4a0f4973 100644 --- a/cmd/pad/main.go +++ b/cmd/pad/main.go @@ -3014,6 +3014,10 @@ func searchCmd() *cobra.Command { Total int `json:"total"` Limit int `json:"limit"` Offset int `json:"offset"` + Facets *struct { + Collections map[string]int `json:"collections"` + Statuses map[string]int `json:"statuses"` + } `json:"facets"` } if err := json.Unmarshal(result, &searchResp); err != nil { @@ -3047,6 +3051,23 @@ func searchCmd() *cobra.Command { } else { fmt.Printf("%d result(s)\n", searchResp.Total) } + + // Show facet summary when not filtering by a specific collection + if collection == "" && searchResp.Facets != nil && len(searchResp.Facets.Collections) > 1 { + parts := []string{} + for slug, count := range searchResp.Facets.Collections { + parts = append(parts, fmt.Sprintf("%s: %d", slug, count)) + } + // Simple sort for deterministic output + for i := 0; i < len(parts); i++ { + for j := i + 1; j < len(parts); j++ { + if parts[j] < parts[i] { + parts[i], parts[j] = parts[j], parts[i] + } + } + } + fmt.Printf(" %s\n", strings.Join(parts, ", ")) + } return nil }, }