Skip to content

Commit

Permalink
Update comments slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Mar 12, 2020
1 parent 0a5ab34 commit efdb12d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ BUGS
search for cs --hidden --no-gitignore --no-ignore 英文 cuts in the middle of a rune
score from TF/IDF appears to be negative in some cases (overflow??)
searches in TUI for very large directories clobber each other making UI unresponsive
search cs result_ranker highlights the whole section
highlight on windows command line not escaped correctly
http://localhost:8080/?q=test&ss=300 bug where display is all yellow
Expand Down
19 changes: 11 additions & 8 deletions processor/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,9 @@ func extractRelevantV3(res *fileJob, documentFrequencies map[string]int, relLeng
}
}

sort.Slice(rv3, func(i, j int) bool {
return rv3[i].Start < rv3[j].Start
})

// If we have a single result and its one of those filename matches
// it means we have no content to worry about so just display the first
// If we have a single result and its a filename match which has
// no real start or end position
// it means we have no content to look through so just display the first
// chunk of the file
if len(rv3) == 1 && rv3[0].Start == 0 && rv3[0].End == 0 {
endPos := 300
Expand All @@ -97,6 +94,12 @@ func extractRelevantV3(res *fileJob, documentFrequencies map[string]int, relLeng
}
}

// Sort the results so when we slide around everything is in order
sort.Slice(rv3, func(i, j int) bool {
return rv3[i].Start < rv3[j].Start
})


// Slide around looking for matches that fit in the length
for i := 0; i < len(rv3); i++ {
m := bestMatch{
Expand Down Expand Up @@ -199,8 +202,8 @@ func extractRelevantV3(res *fileJob, documentFrequencies map[string]int, relLeng
p := v.Start + (v.End-v.Start)/2 // comparison word midpoint

// If the word is within a reasonable distance of this word boost the score
// weighted by how common that word is so that matches like a impact the rank
// less than something like cromulent
// weighted by how common that word is so that matches like 'a' impact the rank
// less than something like 'cromulent' which in theory should not occur as much
if abs(mid-p) < (relLength / 3) {
m.Score += 100 / float64(documentFrequencies[v.Word])
}
Expand Down
3 changes: 3 additions & 0 deletions processor/worker_summarize.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func (f *ResultSummarizer) Start() {
}

displayContent := v3.Content

// If the start and end pos are 0 then we don't need to highlight because there is
// nothing to do so, which means its likely to be a filename match with no content
if v3.StartPos != 0 && v3.EndPos != 0 {
displayContent = str.HighlightString(v3.Content, l, fmtBegin, fmtEnd)
}
Expand Down

0 comments on commit efdb12d

Please sign in to comment.