Fix search human-mode output to match engine API response

The Go client struct expected a nested document object and top-level
page/section fields, but the engine returns flat results with metadata
in chunk_metadata. This caused empty display for title, type, tags,
page, and section in human output mode.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-02 16:17:35 +01:00
parent a6bab5e55e
commit 2d179af557
8 changed files with 174 additions and 33 deletions
+19 -20
View File
@@ -67,15 +67,12 @@ func runSearch(cmd *cobra.Command, args []string) error {
var result struct {
Results []struct {
Score float64 `json:"score"`
Document struct {
Title string `json:"title"`
Type string `json:"doc_type"`
Tags []string `json:"tags"`
} `json:"document"`
Page interface{} `json:"page"`
Section string `json:"section"`
Text string `json:"text"`
Score float64 `json:"score"`
Title string `json:"title"`
DocType string `json:"doc_type"`
Tags []string `json:"tags"`
ChunkMetadata map[string]interface{} `json:"chunk_metadata"`
Text string `json:"text"`
} `json:"results"`
}
@@ -103,26 +100,28 @@ func runSearch(cmd *cobra.Command, args []string) error {
snippet = snippet[:200] + "..."
}
fmt.Printf("\n%d. [%.4f] %s\n", i+1, r.Score, r.Document.Title)
fmt.Printf("\n%d. [%.4f] %s\n", i+1, r.Score, r.Title)
location := ""
if r.Page != nil {
location = fmt.Sprintf("Page %v", r.Page)
if page, ok := r.ChunkMetadata["page"]; ok && page != nil {
location = fmt.Sprintf("Page %v", page)
}
if r.Section != "" {
if location != "" {
location += " / "
if section, ok := r.ChunkMetadata["section_header"]; ok && section != nil {
if s, ok := section.(string); ok && s != "" {
if location != "" {
location += " / "
}
location += s
}
location += r.Section
}
if location != "" {
fmt.Printf(" Location: %s\n", location)
}
if r.Document.Type != "" {
fmt.Printf(" Type: %s\n", r.Document.Type)
if r.DocType != "" {
fmt.Printf(" Type: %s\n", r.DocType)
}
if len(r.Document.Tags) > 0 {
fmt.Printf(" Tags: %s\n", joinStrings(r.Document.Tags))
if len(r.Tags) > 0 {
fmt.Printf(" Tags: %s\n", joinStrings(r.Tags))
}
fmt.Printf(" %s\n", snippet)
}