/* Copyright © 2026 Thomas von Dein This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package printer import ( "fmt" "slices" "codeberg.org/scip/esctl/pkg/cfg" "github.com/elastic/go-elasticsearch/v9/typedapi/types" "github.com/tidwall/gjson" ) func PrintDocs(conf *cfg.Config, hits []types.Hit) { if !conf.Ascending { slices.Reverse(hits) } for _, hit := range hits { PrintDoc(conf, hit) } } func PrintDoc(conf *cfg.Config, hit types.Hit) { var score types.Float64 if hit.Score_ != nil { score = *hit.Score_ } docjson := fmt.Sprintf(`{"id":"%s", "score":%0.4f, "index":"%s", "source":%s}`, *hit.Id_, score, hit.Index_, hit.Source_) if conf.Path != "" { value := gjson.Get(docjson, conf.Path) fmt.Println(value.String()) } else { fmt.Println(docjson) } }