summaryrefslogtreecommitdiff
path: root/lib/apps/application.vala
diff options
context:
space:
mode:
Diffstat (limited to 'lib/apps/application.vala')
-rw-r--r--lib/apps/application.vala50
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;
}
}