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.
This commit is contained in:
xarmian
2026-04-15 12:33:37 -04:00
committed by GitHub
parent 91920c9085
commit bf7901ab29
+21
View File
@@ -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
},
}