mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-24 04:03:03 -04:00
Reduce the chances of recurring operations
This commit is contained in:
parent
876e400ab7
commit
e6dd926042
@ -52,11 +52,11 @@ extension SearchOperation {
|
||||
// start sorting search results
|
||||
guard !isCancelled else { return }
|
||||
let searchText = self.searchText.lowercased()
|
||||
let levenshtein = Levenshtein()
|
||||
|
||||
// calculate score for all results
|
||||
for result in results {
|
||||
guard !isCancelled else { break }
|
||||
let levenshtein = Levenshtein()
|
||||
let distance = levenshtein.calculate(result.title.lowercased()[...], searchText[...])
|
||||
if let probability = result.probability?.doubleValue {
|
||||
result.score = NSNumber(floatLiteral: Double(distance) * Foundation.log(7.5576 - 6.4524 * probability))
|
||||
|
Loading…
x
Reference in New Issue
Block a user