diff options
author | matteo4375 <[email protected]> | 2024-10-26 12:31:40 -0400 |
---|---|---|
committer | matteo4375 <[email protected]> | 2024-10-26 12:31:40 -0400 |
commit | f679c48a24b200195ca703bf673a2ae72dc65d1c (patch) | |
tree | 109d20394e9b0d73e5187c69da4772a30b5bd064 /lib/apps/application.vala | |
parent | 4a5308c82e0134f87b7e1ccc56e4fa2778b69fdd (diff) |
apps: add option to include categories in queries
Diffstat (limited to 'lib/apps/application.vala')
-rw-r--r-- | lib/apps/application.vala | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/lib/apps/application.vala b/lib/apps/application.vala index 0a2f73c..07b44e4 100644 --- a/lib/apps/application.vala +++ b/lib/apps/application.vala @@ -47,6 +47,17 @@ public class AstalApps.Application : Object { */ public string[] keywords { owned get { return app.get_keywords(); } } + /** + * `Categories` field from the desktop file. + */ + public string[] categories { owned get { + var categories = app.get_categories(); + if (categories != null) + return categories.split(";"); + + return new string[0]; + } } + internal Application(string id, int? frequency = 0) { Object(app: new DesktopAppInfo(id)); this.frequency = frequency; @@ -94,6 +105,12 @@ public class AstalApps.Application : Object { score.keywords = s; } } + foreach (var category in categories) { + var s = fuzzy_match_string(term, category); + if (s > score.categories) { + score.categories = s; + } + } return score; } @@ -117,6 +134,11 @@ public class AstalApps.Application : Object { score.keywords = keyword.down().contains(term.down()) ? 1 : 0; } } + foreach (var category in categories) { + if (score.categories == 0) { + score.categories = category.down().contains(term.down()) ? 1 : 0; + } + } return score; } @@ -129,16 +151,21 @@ public class AstalApps.Application : Object { .set_member_name("executable").add_string_value(executable) .set_member_name("description").add_string_value(description) .set_member_name("icon_name").add_string_value(icon_name) - .set_member_name("frequency").add_int_value(frequency) - .set_member_name("keywords") - .begin_array(); + .set_member_name("frequency").add_int_value(frequency); + builder.set_member_name("keywords").begin_array(); foreach (string keyword in keywords) { builder.add_string_value(keyword); } + builder.end_array(); + + builder.set_member_name("categories").begin_array(); + foreach (string category in categories) { + builder.add_string_value(category); + } + builder.end_array(); return builder - .end_array() .end_object() .get_root(); } @@ -150,4 +177,5 @@ public struct AstalApps.Score { int executable; int description; int keywords; + int categories; } |