Skip to content

Commit

Permalink
score: clean up debug output (#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
keegancsmith authored Oct 19, 2023
1 parent d8bfea1 commit 4f21415
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions contentprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func (p *contentProvider) chunkMatchScore(secs []DocumentSection, m *ChunkMatch,
maxScore := &debugScore{}

addScore := func(what string, s float64) {
if debug {
if s != 0 && debug {
score.what += fmt.Sprintf("%s:%.2f, ", what, s)
}
score.score += s
Expand Down Expand Up @@ -568,7 +568,7 @@ func (p *contentProvider) chunkMatchScore(secs []DocumentSection, m *ChunkMatch,
}

if debug {
maxScore.what = fmt.Sprintf("score:%f <- %s", maxScore.score, strings.TrimRight(maxScore.what, ", "))
maxScore.what = fmt.Sprintf("score:%.2f <- %s", maxScore.score, strings.TrimSuffix(maxScore.what, ", "))
}

return maxScore.score, maxScore.what
Expand All @@ -584,7 +584,7 @@ func (p *contentProvider) matchScore(secs []DocumentSection, m *LineMatch, langu
maxScore := &debugScore{}

addScore := func(what string, s float64) {
if debug {
if s != 0 && debug {
score.what += fmt.Sprintf("%s:%.2f, ", what, s)
}
score.score += s
Expand Down
6 changes: 5 additions & 1 deletion eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
const maxUInt16 = 0xffff

func (m *FileMatch) addScore(what string, s float64, debugScore bool) {
if debugScore {
if s != 0 && debugScore {
m.Debug += fmt.Sprintf("%s:%.2f, ", what, s)
}
m.Score += s
Expand Down Expand Up @@ -466,6 +466,10 @@ func (d *indexData) scoreFile(fileMatch *FileMatch, doc uint32, mt matchTree, kn
md := d.repoMetaData[d.repos[doc]]
fileMatch.addScore("doc-order", scoreFileOrderFactor*(1.0-float64(doc)/float64(len(d.boundaries))), opts.DebugScore)
fileMatch.addScore("repo-rank", scoreRepoRankFactor*float64(md.Rank)/maxUInt16, opts.DebugScore)

if opts.DebugScore {
fileMatch.Debug = strings.TrimSuffix(fileMatch.Debug, ", ")
}
}

// scoreFileUsingBM25 computes a score for the file match using an approximation to BM25, the most common scoring
Expand Down

0 comments on commit 4f21415

Please sign in to comment.