Skip to content

Commit

Permalink
zoekt: add debug flag to show DebugScore output (#660)
Browse files Browse the repository at this point in the history
Very useful for quick iteration on ranking work.

Test Plan: go run ./cmd/zoekt -debug foo
  • Loading branch information
keegancsmith authored Oct 19, 2023
1 parent 16e2ff8 commit f39e6eb
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cmd/zoekt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,23 @@ func displayMatches(files []zoekt.FileMatch, pat string, withRepo bool, list boo
r = f.Repository + "/"
}
if list {
fmt.Printf("%s%s\n", r, f.FileName)
fmt.Printf("%s%s%s\n", r, f.FileName, addTabIfNonEmpty(f.Debug))
continue
}

for _, m := range f.LineMatches {
fmt.Printf("%s%s:%d:%s\n", r, f.FileName, m.LineNumber, m.Line)
fmt.Printf("%s%s:%d:%s%s\n", r, f.FileName, m.LineNumber, m.Line, addTabIfNonEmpty(f.Debug))
}
}
}

func addTabIfNonEmpty(s string) string {
if s != "" {
return "\t" + s
}
return s
}

func loadShard(fn string, verbose bool) (zoekt.Searcher, error) {
f, err := os.Open(fn)
if err != nil {
Expand Down Expand Up @@ -130,6 +137,7 @@ func main() {
cpuProfile := flag.String("cpu_profile", "", "write cpu profile to `file`")
fullProfile := flag.String("full_profile", "", "write full profile to `file`")
profileTime := flag.Duration("profile_time", time.Second, "run this long to gather stats.")
debug := flag.Bool("debug", false, "show debugscore output.")
verbose := flag.Bool("v", false, "print some background data")
withRepo := flag.Bool("r", false, "print the repo before the file name")
list := flag.Bool("l", false, "print matching filenames only")
Expand Down Expand Up @@ -170,7 +178,9 @@ func main() {
log.Println("query:", query)
}

var sOpts zoekt.SearchOptions
sOpts := zoekt.SearchOptions{
DebugScore: *debug,
}
sres, err := searcher.Search(context.Background(), query, &sOpts)
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit f39e6eb

Please sign in to comment.