fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

debug: add "score" to debug string (#470)

This moves the "score" prefix from the template to the debug strings.
This way we have a consistent behaviour in Sourcegraph and Zoekt.

+20 -8
+13 -4
contentprovider.go
··· 497 497 498 498 addScore := func(what string, s float64) { 499 499 if debug { 500 - score.what += fmt.Sprintf("%s:%f, ", what, s) 500 + score.what += fmt.Sprintf("%s:%.2f, ", what, s) 501 501 } 502 502 score.score += s 503 503 } ··· 562 562 } 563 563 } 564 564 565 - return maxScore.score, strings.TrimRight(maxScore.what, ", ") 565 + if debug { 566 + maxScore.what = fmt.Sprintf("score:%f <- %s", maxScore.score, strings.TrimRight(maxScore.what, ", ")) 567 + } 568 + 569 + return maxScore.score, maxScore.what 566 570 } 567 571 568 572 func (p *contentProvider) matchScore(secs []DocumentSection, m *LineMatch, language string, debug bool) (float64, string) { ··· 576 580 577 581 addScore := func(what string, s float64) { 578 582 if debug { 579 - score.what += fmt.Sprintf("%s:%f, ", what, s) 583 + score.what += fmt.Sprintf("%s:%.2f, ", what, s) 580 584 } 581 585 score.score += s 582 586 } ··· 636 640 maxScore.what = score.what 637 641 } 638 642 } 639 - return maxScore.score, strings.TrimRight(maxScore.what, ", ") 643 + 644 + if debug { 645 + maxScore.what = fmt.Sprintf("score:%.2f <- %s", maxScore.score, strings.TrimSuffix(maxScore.what, ", ")) 646 + } 647 + 648 + return maxScore.score, maxScore.what 640 649 } 641 650 642 651 // scoreKind boosts a match based on the combination of language and kind. The
+5 -1
eval.go
··· 32 32 33 33 func (m *FileMatch) addScore(what string, s float64, debugScore bool) { 34 34 if debugScore { 35 - m.Debug += fmt.Sprintf("%s:%f, ", what, s) 35 + m.Debug += fmt.Sprintf("%s:%.2f, ", what, s) 36 36 } 37 37 m.Score += s 38 38 } ··· 394 394 395 395 repoMatchCount += len(fileMatch.LineMatches) 396 396 repoMatchCount += matchedChunkRanges 397 + 398 + if opts.DebugScore { 399 + fileMatch.Debug = fmt.Sprintf("score:%.2f <- %s", fileMatch.Score, fileMatch.Debug) 400 + } 397 401 398 402 res.Files = append(res.Files, fileMatch) 399 403 res.Stats.MatchCount += len(fileMatch.LineMatches)
+2 -3
web/templates.go
··· 220 220 {{else}}.{{end}} 221 221 </h5> 222 222 {{range .FileMatches}} 223 - {{$showScoreDebug := .ScoreDebug}} 224 223 <table class="table table-hover table-condensed"> 225 224 <thead> 226 225 <tr> 227 226 <th> 228 227 {{if .URL}}<a name="{{.ResultID}}" class="result"></a><a href="{{.URL}}" >{{else}}<a name="{{.ResultID}}">{{end}} 229 228 <small> 230 - {{.Repo}}:{{.FileName}} {{if $showScoreDebug}}<i>(score:{{.Score}} <-- {{.ScoreDebug}})</i>{{end}}</a>: 229 + {{.Repo}}:{{.FileName}} {{if .ScoreDebug}}<i>({{.ScoreDebug}})</i>{{end}}</a>: 231 230 <span style="font-weight: normal">[ {{if .Branches}}{{range .Branches}}<span class="label label-default">{{.}}</span>,{{end}}{{end}} ]</span> 232 231 {{if .Language}}<button 233 232 title="restrict search to files written in {{.Language}}" ··· 242 241 {{range .Matches}} 243 242 <tr> 244 243 <td style="background-color: rgba(238, 238, 255, 0.6);"> 245 - <pre class="inline-pre"><span class="noselect">{{if .URL}}<a href="{{.URL}}">{{end}}<u>{{.LineNum}}</u>{{if .URL}}</a>{{end}}: </span>{{range .Fragments}}{{LimitPre 100 .Pre}}<b>{{.Match}}</b>{{LimitPost 100 .Post}}{{end}} {{if $showScoreDebug}}<i>(score:{{.Score}} <-- {{.ScoreDebug}})</i>{{end}}</pre> 244 + <pre class="inline-pre"><span class="noselect">{{if .URL}}<a href="{{.URL}}">{{end}}<u>{{.LineNum}}</u>{{if .URL}}</a>{{end}}: </span>{{range .Fragments}}{{LimitPre 100 .Pre}}<b>{{.Match}}</b>{{LimitPost 100 .Post}}{{end}} {{if .ScoreDebug}}<i>({{.ScoreDebug}})</i>{{end}}</pre> 246 245 </td> 247 246 </tr> 248 247 {{end}}