1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-28 11:35:35 +03:00
vimr/VimR/Scorer.swift

34 lines
762 B
Swift
Raw Normal View History

/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Foundation
class Scorer {
2016-09-25 18:50:33 +03:00
static func score(_ target: String, pattern: String) -> Int {
let wf = Matcher.wagnerFisherDistance(target, pattern: pattern)
2016-09-07 23:06:17 +03:00
let fuzzy = Matcher.fuzzyIgnoringCase(target, pattern: pattern)
let upper = Matcher.numberOfUppercaseMatches(target, pattern: pattern)
let exactMatch = Matcher.exactMatchIgnoringCase(target, pattern: pattern)
2016-09-08 21:16:37 +03:00
let exactScore: Int
switch exactMatch {
case .none:
exactScore = 0
case .exact:
return 100
case .prefix, .contains, .suffix:
exactScore = 5
}
2016-09-08 21:16:37 +03:00
let wfScore = 0 - (wf / 10)
return exactScore
+ wfScore
+ fuzzy.matches
+ 2 * upper
}
}