adjust scoring weights

pull/137/head
Simon Let 6 years ago
parent 1910eb93d5
commit cfaec01c5e
  1. 30
      cmd/cli/item.go

@ -265,14 +265,24 @@ func properMatch(str, term, padChar string) bool {
// newItemFromRecordForQuery creates new item from record based on given query // newItemFromRecordForQuery creates new item from record based on given query
// returns error if the query doesn't match the record // returns error if the query doesn't match the record
func newItemFromRecordForQuery(record records.CliRecord, query query, debug bool) (item, error) { func newItemFromRecordForQuery(record records.CliRecord, query query, debug bool) (item, error) {
const hitScore = 1.2 // Use numbers that won't add up to same score for any number of query words
const hitScoreConsecutive = 0.1 const hitScore = 1.307
const properMatchScore = 0.3 const properMatchScore = 0.603
const actualPwdScore = 0.9 const hitScoreConsecutive = 0.002
const nonZeroExitCodeScorePenalty = 0.4
const sameGitRepoScore = 0.6 // Host penalty
// const sameGitRepoScoreExtra = 0.0 var actualPwdScore = 0.9
const differentHostScorePenalty = 0.2 var sameGitRepoScore = 0.8
var nonZeroExitCodeScorePenalty = 0.4
var differentHostScorePenalty = 0.2
reduceHostPenalty := false
if reduceHostPenalty {
actualPwdScore = 0.9
sameGitRepoScore = 0.7
nonZeroExitCodeScorePenalty = 0.4
differentHostScorePenalty = 0.1
}
const timeScoreCoef = 1e-13 const timeScoreCoef = 1e-13
// nonZeroExitCodeScorePenalty + differentHostScorePenalty // nonZeroExitCodeScorePenalty + differentHostScorePenalty
@ -286,7 +296,8 @@ func newItemFromRecordForQuery(record records.CliRecord, query query, debug bool
anyHit = true anyHit = true
if termHit == false { if termHit == false {
score += hitScore score += hitScore
} else { } else if len(term) > 1 {
// only count consecutive matches for queries longer than 1
score += hitScoreConsecutive score += hitScoreConsecutive
} }
termHit = true termHit = true
@ -294,7 +305,6 @@ func newItemFromRecordForQuery(record records.CliRecord, query query, debug bool
score += properMatchScore score += properMatchScore
} }
cmd = strings.ReplaceAll(cmd, term, highlightMatch(term)) cmd = strings.ReplaceAll(cmd, term, highlightMatch(term))
// NO continue
} }
} }
// DISPLAY > cmdline // DISPLAY > cmdline

Loading…
Cancel
Save