From 6bd4d5131e1d8ded4134e9cd7e415d14d8b07b31 Mon Sep 17 00:00:00 2001 From: jraedisch Date: Sat, 04 Apr 2026 09:59:58 +0000 Subject: [PATCH] pretty-print search JSON output, fix collection NSID in README Co-Authored-By: Claude Opus 4.6 (1M context) --- README.md | 2 +- main.go | 44 +++++--------------------------------------- 2 file(s) changed, 6 insertion(s)(+), 40 deletion(s)(-) diff --git a/README.md b/README.md --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ { "did": "did:plc:abc123", "handle": "user.bsky.social", - "collection": "feed.post", + "collection": "app.bsky.feed.post", "rkey": "3abc", "text": "Post text...", "score": -0.82, diff --git a/main.go b/main.go --- a/main.go +++ b/main.go @@ -109,47 +109,13 @@ log.Fatalf("search failed: %v", err) } - fmt.Printf("%d results in %s\n\n", len(resp.Results), dur.Round(time.Millisecond)) + fmt.Fprintf(os.Stderr, "%d results in %s\n", len(resp.Results), dur.Round(time.Millisecond)) - if len(resp.Clusters) > 0 { - for _, cl := range resp.Clusters { - topics := "(no topics)" - if len(cl.Topics) > 0 { - topics = strings.Join(cl.Topics, ", ") - } - fmt.Printf("── Cluster %d: %s (%d posts) ──\n", cl.ID, topics, cl.Size) - for _, ri := range cl.ResultIndices { - if ri < len(resp.Results) { - r := resp.Results[ri] - printResult(r) - } - } - fmt.Println() - } - // Print unclustered results - for _, r := range resp.Results { - if r.ClusterID == nil { - printResult(r) - } - } - } else { - for _, r := range resp.Results { - printResult(r) - } + enc := json.NewEncoder(os.Stdout) + enc.SetIndent("", " ") + if err := enc.Encode(resp); err != nil { + log.Fatalf("encode response: %v", err) } -} - -func printResult(r SearchResult) { - handle := r.Handle - if handle == "" { - handle = r.DID - } - text := r.Text - if len(text) > 200 { - text = text[:200] + "..." - } - text = strings.ReplaceAll(text, "\n", " ") - fmt.Printf(" %.4f @%-30s %s\n", r.Score, handle, text) } func stream(baseURL, token string, outFile *os.File) error { -- tangled.sh