From 856f6d06464f5ced12be8dd1a288daccda44c3e5 Mon Sep 17 00:00:00 2001 From: kotontrion Date: Sun, 13 Oct 2024 08:40:10 +0200 Subject: apps: fix style --- lib/apps/apps.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/apps/apps.vala') diff --git a/lib/apps/apps.vala b/lib/apps/apps.vala index 2a0d507..b07961e 100644 --- a/lib/apps/apps.vala +++ b/lib/apps/apps.vala @@ -8,7 +8,7 @@ public class Apps : Object { public bool show_hidden { get; set; } public List list { owned get { return _list.copy(); } } - public double min_score { get; set; default = 0.5; } + public int min_score { get; set; default = 0; } public double name_multiplier { get; set; default = 2; } public double entry_multiplier { get; set; default = 1; } -- cgit v1.2.3 From 0cb8733f31defcf2f7158d23c058fbb92a580215 Mon Sep 17 00:00:00 2001 From: Aylur Date: Tue, 15 Oct 2024 18:58:12 +0000 Subject: docs: apps doc comments docs: apps doc comments --- lib/apps/apps.vala | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 4 deletions(-) (limited to 'lib/apps/apps.vala') diff --git a/lib/apps/apps.vala b/lib/apps/apps.vala index b07961e..c96a2b2 100644 --- a/lib/apps/apps.vala +++ b/lib/apps/apps.vala @@ -1,23 +1,70 @@ -namespace AstalApps { -public class Apps : Object { +public class AstalApps.Apps : Object { private string cache_directory; private string cache_file; private List _list; private HashTable frequents { get; private set; } + /** + * Indicates wether hidden applications should included in queries. + */ public bool show_hidden { get; set; } + + /** + * Full list of available applications. + */ public List list { owned get { return _list.copy(); } } + /** + * The minimum score the application has to meet in order to be included in queries. + */ public int min_score { get; set; default = 0; } + /** + * Extra multiplier to apply when matching the `name` of an application. + * Defaults to `2` + */ public double name_multiplier { get; set; default = 2; } + + /** + * Extra multiplier to apply when matching the entry of an application. + * Defaults to `1` + */ public double entry_multiplier { get; set; default = 1; } + + /** + * Extra multiplier to apply when matching the executable of an application. + * Defaults to `1` + */ public double executable_multiplier { get; set; default = 1; } + + /** + * Extra multiplier to apply when matching the description of an application. + * Defaults to `0.5` + */ public double description_multiplier { get; set; default = 0.5; } + /** + * Consider the name of an application during queries. + * Defaults to `true` + */ public bool include_name { get; set; default = true; } + + /** + * Consider the entry of an application during queries. + * Defaults to `false` + */ public bool include_entry { get; set; default = false; } + + /** + * Consider the executable of an application during queries. + * Defaults to `false` + */ public bool include_executable { get; set; default = false; } + + /** + * Consider the description of an application during queries. + * Defaults to `false` + */ public bool include_description { get; set; default = false; } construct { @@ -65,7 +112,7 @@ public class Apps : Object { return r; } - public List query(string? search = "", bool exact = false) { + internal List query(string? search = "", bool exact = false) { if (search == null) search = ""; @@ -114,14 +161,23 @@ public class Apps : Object { return arr; } + /** + * Query the `list` of applications with a fuzzy matching algorithm. + */ public List fuzzy_query(string? search = "") { return query(search, false); } + /** + * Query the `list` of applications with a simple string matching algorithm. + */ public List exact_query(string? search = "") { return query(search, true); } + /** + * Reload the `list` of Applications. + */ public void reload() { var arr = AppInfo.get_all(); @@ -169,4 +225,3 @@ public class Apps : Object { } } } -} -- cgit v1.2.3 From 2ad95e05d83a455bb30503ca4ca0aa8356ea5ff7 Mon Sep 17 00:00:00 2001 From: kotontrion Date: Wed, 16 Oct 2024 09:49:37 +0200 Subject: apps: fuzzy: reduce panalty for not matching --- lib/apps/apps.vala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/apps/apps.vala') diff --git a/lib/apps/apps.vala b/lib/apps/apps.vala index b07961e..acab155 100644 --- a/lib/apps/apps.vala +++ b/lib/apps/apps.vala @@ -8,7 +8,7 @@ public class Apps : Object { public bool show_hidden { get; set; } public List list { owned get { return _list.copy(); } } - public int min_score { get; set; default = 0; } + public double min_score { get; set; default = 0; } public double name_multiplier { get; set; default = 2; } public double entry_multiplier { get; set; default = 1; } @@ -61,7 +61,6 @@ public class Apps : Object { r += am.executable * executable_multiplier; if (include_description) r += am.description * description_multiplier; - return r; } -- cgit v1.2.3 From e6250c7a4366da033d98a67b426ae5e08aa6f712 Mon Sep 17 00:00:00 2001 From: Aylur Date: Thu, 24 Oct 2024 20:25:33 +0000 Subject: lib(apps): make scoring mechanism public resolves #54 --- lib/apps/apps.vala | 55 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 17 deletions(-) (limited to 'lib/apps/apps.vala') diff --git a/lib/apps/apps.vala b/lib/apps/apps.vala index bbe07c6..ac48121 100644 --- a/lib/apps/apps.vala +++ b/lib/apps/apps.vala @@ -96,22 +96,38 @@ public class AstalApps.Apps : Object { reload(); } - private double score (string search, Application a, bool exact) { - var am = exact ? a.exact_match(search) : a.fuzzy_match(search); + private double score(string search, Application a, SearchAlgorithm alg) { + var s = Score(); double r = 0; - if (include_name) - r += am.name * name_multiplier; - if (include_entry) - r += am.entry * entry_multiplier; - if (include_executable) - r += am.executable * executable_multiplier; - if (include_description) - r += am.description * description_multiplier; + if (alg == FUZZY) s = a.fuzzy_match(search); + if (alg == EXACT) s = a.exact_match(search); + + if (include_name) r += s.name * name_multiplier; + if (include_entry) r += s.entry * entry_multiplier; + if (include_executable) r += s.executable * executable_multiplier; + if (include_description) r += s.description * description_multiplier; + return r; } - internal List query(string? search = "", bool exact = false) { + /** + * Calculate a score for an application using fuzzy matching algorithm. + * Taking this Apps' include settings into consideration . + */ + public double fuzzy_score(string search, Application a) { + return score(search, a, FUZZY); + } + + /** + * Calculate a score for an application using exact string algorithm. + * Taking this Apps' include settings into consideration . + */ + public double exact_score(string search, Application a) { + return score(search, a, EXACT); + } + + internal List query(string? search = "", SearchAlgorithm alg = FUZZY) { if (search == null) search = ""; @@ -129,7 +145,7 @@ public class AstalApps.Apps : Object { // single character, sort by frequency and exact match if (search.length == 1) { foreach (var app in list) { - if (score(search, app, true) == 0) + if (score(search, app, alg) == 0) arr.remove(app); } @@ -142,14 +158,14 @@ public class AstalApps.Apps : Object { // filter foreach (var app in list) { - if (score(search, app, exact) < min_score) + if (score(search, app, alg) < min_score) arr.remove(app); } // sort by score, frequency arr.sort_with_data((a, b) => { - var s1 = score(search, a, exact); - var s2 = score(search, b, exact); + var s1 = score(search, a, alg); + var s2 = score(search, b, alg); if (s1 == s2) return (int)b.frequency - (int)a.frequency; @@ -164,14 +180,14 @@ public class AstalApps.Apps : Object { * Query the `list` of applications with a fuzzy matching algorithm. */ public List fuzzy_query(string? search = "") { - return query(search, false); + return query(search, FUZZY); } /** * Query the `list` of applications with a simple string matching algorithm. */ public List exact_query(string? search = "") { - return query(search, true); + return query(search, EXACT); } /** @@ -224,3 +240,8 @@ public class AstalApps.Apps : Object { } } } + +private enum AstalApps.SearchAlgorithm { + EXACT, + FUZZY, +} -- cgit v1.2.3 From 61727b01ba06f876664addca83e774cb2bad9ce9 Mon Sep 17 00:00:00 2001 From: matteo4375 <160355435+matteo4375@users.noreply.github.com> Date: Thu, 24 Oct 2024 17:39:38 -0400 Subject: apps: add option to include keywords in queries (#56) --- lib/apps/apps.vala | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/apps/apps.vala') diff --git a/lib/apps/apps.vala b/lib/apps/apps.vala index ac48121..dde7d44 100644 --- a/lib/apps/apps.vala +++ b/lib/apps/apps.vala @@ -43,6 +43,12 @@ public class AstalApps.Apps : Object { */ public double description_multiplier { get; set; default = 0.5; } + /** + * Extra multiplier to apply when matching the keywords of an application. + * Defaults to `0.5` + */ + public double keywords_multiplier { get; set; default = 0.5; } + /** * Consider the name of an application during queries. * Defaults to `true` @@ -67,6 +73,12 @@ public class AstalApps.Apps : Object { */ public bool include_description { get; set; default = false; } + /** + * Consider the keywords of an application during queries. + * Defaults to `false` + */ + public bool include_keywords { get; set; default = false; } + construct { cache_directory = Environment.get_user_cache_dir() + "/astal"; cache_file = cache_directory + "/apps-frequents.json"; @@ -107,6 +119,7 @@ public class AstalApps.Apps : Object { if (include_entry) r += s.entry * entry_multiplier; if (include_executable) r += s.executable * executable_multiplier; if (include_description) r += s.description * description_multiplier; + if (include_keywords) r += s.keywords * keywords_multiplier; return r; } -- cgit v1.2.3