diff options
author | Kevin <[email protected]> | 2024-10-14 10:24:22 -0300 |
---|---|---|
committer | GitHub <[email protected]> | 2024-10-14 10:24:22 -0300 |
commit | 906e9a30029e4547b73cf5bc566c98bd9198dc0e (patch) | |
tree | 694b487ea9231511caf7655b0547b2048e43148b /lib/apps/application.vala | |
parent | 18df91b128f6ca8850e39cb53b8536a8207e1741 (diff) | |
parent | bdb23e20f171da7c769cba9e393d7e406e563a78 (diff) |
Merge branch 'Aylur:main' into main
Diffstat (limited to 'lib/apps/application.vala')
-rw-r--r-- | lib/apps/application.vala | 50 |
1 files changed, 8 insertions, 42 deletions
diff --git a/lib/apps/application.vala b/lib/apps/application.vala index 5748fc6..75ff6b2 100644 --- a/lib/apps/application.vala +++ b/lib/apps/application.vala @@ -32,13 +32,13 @@ public class Application : Object { public Score fuzzy_match(string term) { var score = Score(); if (name != null) - score.name = levenshtein(term, name); + score.name = fuzzy_match_string(term, name); if (entry != null) - score.entry = levenshtein(term, entry); + score.entry = fuzzy_match_string(term, entry); if (executable != null) - score.executable = levenshtein(term, executable); + score.executable = fuzzy_match_string(term, executable); if (description != null) - score.description = levenshtein(term, description); + score.description = fuzzy_match_string(term, description); return score; } @@ -75,44 +75,10 @@ int min3(int a, int b, int c) { return (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c); } -double levenshtein(string s1, string s2) { - int len1 = s1.length; - int len2 = s2.length; - - int[, ] d = new int[len1 + 1, len2 + 1]; - - for (int i = 0; i <= len1; i++) { - d[i, 0] = i; - } - for (int j = 0; j <= len2; j++) { - d[0, j] = j; - } - - for (int i = 1; i <= len1; i++) { - for (int j = 1; j <= len2; j++) { - int cost = (s1[i - 1] == s2[j - 1]) ? 0 : 1; - d[i, j] = min3( - d[i - 1, j] + 1, // deletion - d[i, j - 1] + 1, // insertion - d[i - 1, j - 1] + cost // substitution - ); - } - } - - var distance = d[len1, len2]; - int max_len = len1 > len2 ? len1 : len2; - - if (max_len == 0) { - return 1.0; - } - - return 1.0 - ((double)distance / max_len); -} - public struct Score { - double name; - double entry; - double executable; - double description; + int name; + int entry; + int executable; + int description; } } |