From ad99ffc44dcbb919c45ae763be8fc78d64f28711 Mon Sep 17 00:00:00 2001 From: italo-capasso Date: Mon, 11 Aug 2025 15:15:07 -0500 Subject: [PATCH 01/14] Give extra score if the query matches exactly or partially the name or id of the app package --- src/Core/Package.vala | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Core/Package.vala b/src/Core/Package.vala index a9f05cb49..2c82f07c2 100644 --- a/src/Core/Package.vala +++ b/src/Core/Package.vala @@ -607,12 +607,22 @@ public class AppCenterCore.Package : Object { uint score = 0; foreach (var query in queries) { var query_score = component.search_matches (query); - if (query_score == 0) { - score = 0; - break; + var id_down = component.name.down (); + var name_down = component.name.down (); + var query_down = query.down (); + + // Give extra score value if query is a substring + // or if it matches exactly the component name or id + if (query_down == name_down || id_down == query_down) { + query_score = 100 * queries.length; + } else if ( + name_down.contains (query.down ()) || + id_down.contains (query.down ()) + ) { + query_score = 50 * queries.length; + } } - score += query_score; } cached_search_score = score / queries.length; @@ -699,11 +709,11 @@ public class AppCenterCore.Package : Object { break; case AppStream.IconKind.UNKNOWN: - warning ("'%s' is an unknown kind of AppStream icon", _icon.get_name ()); + //warning ("'%s' is an unknown kind of AppStream icon", _icon.get_name ()); break; case AppStream.IconKind.REMOTE: - warning ("'%s' is a remote AppStream icon", _icon.get_name ()); + //warning ("'%s' is a remote AppStream icon", _icon.get_name ()); break; } } From 579482dc415d821c42bbb5400cc99a951960f1f4 Mon Sep 17 00:00:00 2001 From: italo-capasso Date: Mon, 11 Aug 2025 15:16:00 -0500 Subject: [PATCH 02/14] Add an extra joined up token if there are more than one token in the search query. --- src/Core/SearchEngine.vala | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Core/SearchEngine.vala b/src/Core/SearchEngine.vala index 0d22c3eda..1021cb7d1 100644 --- a/src/Core/SearchEngine.vala +++ b/src/Core/SearchEngine.vala @@ -57,6 +57,13 @@ public class AppCenterCore.SearchEngine : Object { public void search (string query, AppStream.Category? category) { this.query = pool.build_search_tokens (query); + // If there are multiple tokens, add an aditional joined query token + if (this.query.length > 1) { + var joined_query = query.replace (" ", ""); + critical (joined_query); + this.query.resize (this.query.length + 1); + this.query[this.query.length - 1] = joined_query; + } this.category = category; packages.items_changed (0, packages.n_items, packages.n_items); } From d6fe2bc873a59bd8cc1fea9981037c5c7e23d18d Mon Sep 17 00:00:00 2001 From: italo-capasso Date: Mon, 11 Aug 2025 15:51:15 -0500 Subject: [PATCH 03/14] Eliminate magic numbers. Fix linting. --- src/Core/Package.vala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Core/Package.vala b/src/Core/Package.vala index 2c82f07c2..d863e3e16 100644 --- a/src/Core/Package.vala +++ b/src/Core/Package.vala @@ -102,6 +102,8 @@ public class AppCenterCore.Package : Object { public const string RUNTIME_UPDATES_ID = "xxx-runtime-updates"; public const string LOCAL_ID_SUFFIX = ".appcenter-local"; public const string DEFAULT_PRICE_DOLLARS = "1"; + public const uint EXACT_MATCH_SCORE = 100; + public const uint PARTIAL_MATCH_SCORE = 50; public AppStream.Component component { get; protected set; } public ChangeInformation change_information { public get; private set; } @@ -615,12 +617,12 @@ public class AppCenterCore.Package : Object { // Give extra score value if query is a substring // or if it matches exactly the component name or id if (query_down == name_down || id_down == query_down) { - query_score = 100 * queries.length; + query_score = EXACT_MATCH_SCORE * queries.length; } else if ( name_down.contains (query.down ()) || id_down.contains (query.down ()) ) { - query_score = 50 * queries.length; + query_score = PARTIAL_MATCH_SCORE * queries.length; } } score += query_score; From 6a41d19385f172ecb8ad8adfac7e19553c5b512f Mon Sep 17 00:00:00 2001 From: italo-capasso Date: Thu, 11 Sep 2025 21:41:54 -0500 Subject: [PATCH 04/14] Uncommented accidentally commented lines. --- src/Core/Package.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core/Package.vala b/src/Core/Package.vala index 55c805955..a81af5c90 100644 --- a/src/Core/Package.vala +++ b/src/Core/Package.vala @@ -713,11 +713,11 @@ public class AppCenterCore.Package : Object { break; case AppStream.IconKind.UNKNOWN: - //warning ("'%s' is an unknown kind of AppStream icon", _icon.get_name ()); + warning ("'%s' is an unknown kind of AppStream icon", _icon.get_name ()); break; case AppStream.IconKind.REMOTE: - //warning ("'%s' is a remote AppStream icon", _icon.get_name ()); + warning ("'%s' is a remote AppStream icon", _icon.get_name ()); break; } } From 2c1a6a3e1cef9e1555af0cfe7ea5497ce41f84ed Mon Sep 17 00:00:00 2001 From: italo-capasso Date: Thu, 11 Sep 2025 21:44:07 -0500 Subject: [PATCH 05/14] Fixed wrong assignment on id_down variable. --- src/Core/Package.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Package.vala b/src/Core/Package.vala index a81af5c90..797460cbd 100644 --- a/src/Core/Package.vala +++ b/src/Core/Package.vala @@ -610,7 +610,7 @@ public class AppCenterCore.Package : Object { foreach (var query in queries) { var query_score = component.search_matches (query); if (query_score == 0) { - var id_down = component.name.down (); + var id_down = component.id.down (); var name_down = component.name.down (); var query_down = query.down (); From f87209ffef7924c4cc48e3e871b0daf502ac1e69 Mon Sep 17 00:00:00 2001 From: "Italo F. Capasso B." <44873757+edwood-grant@users.noreply.github.com> Date: Thu, 18 Sep 2025 19:02:37 -0500 Subject: [PATCH 06/14] Reversed query equality statement for consistency Co-authored-by: Leo --- src/Core/Package.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Package.vala b/src/Core/Package.vala index 797460cbd..1e114b39c 100644 --- a/src/Core/Package.vala +++ b/src/Core/Package.vala @@ -616,7 +616,7 @@ public class AppCenterCore.Package : Object { // Give extra score value if query is a substring // or if it matches exactly the component name or id - if (query_down == name_down || id_down == query_down) { + if (query_down == name_down || query_down == id_down) { query_score = EXACT_MATCH_SCORE * queries.length; } else if ( name_down.contains (query.down ()) || From 25a33ecf5e6ca7ef58106440ffba11a2066d3009 Mon Sep 17 00:00:00 2001 From: "Italo F. Capasso B." <44873757+edwood-grant@users.noreply.github.com> Date: Thu, 18 Sep 2025 19:03:08 -0500 Subject: [PATCH 07/14] Use query_down variable instead of invoking the method Co-authored-by: Leo --- src/Core/Package.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Package.vala b/src/Core/Package.vala index 1e114b39c..2091b4c1e 100644 --- a/src/Core/Package.vala +++ b/src/Core/Package.vala @@ -619,7 +619,7 @@ public class AppCenterCore.Package : Object { if (query_down == name_down || query_down == id_down) { query_score = EXACT_MATCH_SCORE * queries.length; } else if ( - name_down.contains (query.down ()) || + name_down.contains (query_down) || id_down.contains (query.down ()) ) { query_score = PARTIAL_MATCH_SCORE * queries.length; From e33a58c2d43e5f5e504321eb3df7ecd537435da3 Mon Sep 17 00:00:00 2001 From: "Italo F. Capasso B." <44873757+edwood-grant@users.noreply.github.com> Date: Thu, 18 Sep 2025 19:03:15 -0500 Subject: [PATCH 08/14] Use query_down variable instead of invoking the method Co-authored-by: Leo --- src/Core/Package.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Package.vala b/src/Core/Package.vala index 2091b4c1e..2cbbad3f1 100644 --- a/src/Core/Package.vala +++ b/src/Core/Package.vala @@ -620,7 +620,7 @@ public class AppCenterCore.Package : Object { query_score = EXACT_MATCH_SCORE * queries.length; } else if ( name_down.contains (query_down) || - id_down.contains (query.down ()) + id_down.contains (query_down) ) { query_score = PARTIAL_MATCH_SCORE * queries.length; } From 4a24cbe89c43ed2e396413f7723dc7ed6f4b8a0e Mon Sep 17 00:00:00 2001 From: "Italo F. Capasso B." <44873757+edwood-grant@users.noreply.github.com> Date: Thu, 18 Sep 2025 19:04:03 -0500 Subject: [PATCH 09/14] Add extra spacing before an if Co-authored-by: Leo --- src/Core/Package.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Core/Package.vala b/src/Core/Package.vala index 2cbbad3f1..3a786d4f3 100644 --- a/src/Core/Package.vala +++ b/src/Core/Package.vala @@ -609,6 +609,7 @@ public class AppCenterCore.Package : Object { uint score = 0; foreach (var query in queries) { var query_score = component.search_matches (query); + if (query_score == 0) { var id_down = component.id.down (); var name_down = component.name.down (); From 298ada53aaba09b043f6e7b48825d3829a619120 Mon Sep 17 00:00:00 2001 From: "Italo F. Capasso B." <44873757+edwood-grant@users.noreply.github.com> Date: Thu, 18 Sep 2025 19:05:04 -0500 Subject: [PATCH 10/14] Added extra spacing at end of if statement Co-authored-by: Leo --- src/Core/Package.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Core/Package.vala b/src/Core/Package.vala index 3a786d4f3..177641125 100644 --- a/src/Core/Package.vala +++ b/src/Core/Package.vala @@ -626,6 +626,7 @@ public class AppCenterCore.Package : Object { query_score = PARTIAL_MATCH_SCORE * queries.length; } } + score += query_score; } cached_search_score = score / queries.length; From 23e1bd59c2d82463c473f783f11287d1d5bbde07 Mon Sep 17 00:00:00 2001 From: "Italo F. Capasso B." <44873757+edwood-grant@users.noreply.github.com> Date: Wed, 29 Oct 2025 18:30:54 +0000 Subject: [PATCH 11/14] Removed a unnecessary critical message Co-authored-by: Leonhard --- src/Core/SearchEngine.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Core/SearchEngine.vala b/src/Core/SearchEngine.vala index 1021cb7d1..d3d91052b 100644 --- a/src/Core/SearchEngine.vala +++ b/src/Core/SearchEngine.vala @@ -60,7 +60,6 @@ public class AppCenterCore.SearchEngine : Object { // If there are multiple tokens, add an aditional joined query token if (this.query.length > 1) { var joined_query = query.replace (" ", ""); - critical (joined_query); this.query.resize (this.query.length + 1); this.query[this.query.length - 1] = joined_query; } From 8678b1538936fd5a93d620ed291bebed1f57e815 Mon Sep 17 00:00:00 2001 From: "Italo F. Capasso B." <44873757+edwood-grant@users.noreply.github.com> Date: Wed, 29 Oct 2025 18:31:29 +0000 Subject: [PATCH 12/14] Simplified joined query statement syntax Co-authored-by: Leonhard --- src/Core/SearchEngine.vala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Core/SearchEngine.vala b/src/Core/SearchEngine.vala index d3d91052b..4508c24f6 100644 --- a/src/Core/SearchEngine.vala +++ b/src/Core/SearchEngine.vala @@ -60,8 +60,7 @@ public class AppCenterCore.SearchEngine : Object { // If there are multiple tokens, add an aditional joined query token if (this.query.length > 1) { var joined_query = query.replace (" ", ""); - this.query.resize (this.query.length + 1); - this.query[this.query.length - 1] = joined_query; + this.query += joined_query; } this.category = category; packages.items_changed (0, packages.n_items, packages.n_items); From 90f764f9daac7b15991bc59973af4171cb7844b1 Mon Sep 17 00:00:00 2001 From: italo-capasso Date: Thu, 30 Oct 2025 07:39:27 -0500 Subject: [PATCH 13/14] Added comment to explain the joined token addition --- src/Core/SearchEngine.vala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Core/SearchEngine.vala b/src/Core/SearchEngine.vala index 4508c24f6..d98227689 100644 --- a/src/Core/SearchEngine.vala +++ b/src/Core/SearchEngine.vala @@ -57,7 +57,15 @@ public class AppCenterCore.SearchEngine : Object { public void search (string query, AppStream.Category? category) { this.query = pool.build_search_tokens (query); - // If there are multiple tokens, add an aditional joined query token + /* + * If there are multiple tokens, add an additional joined query token. + * This is done because users tend to search queries for apps that have + * one name as separate with spaces. An example would be "LibreOffice", + * usually being searched as "Libre Office". Searching this shows the app + * as the 17th result instead of the first without a joined query. With + * the joined query (e.g. the search being "Libre Office LibreOffice") it + * will show up as the first search result. + */ if (this.query.length > 1) { var joined_query = query.replace (" ", ""); this.query += joined_query; From 3dca57a1a3f70182ff0b8a2daf8411f686d5ec65 Mon Sep 17 00:00:00 2001 From: italo-capasso Date: Thu, 30 Oct 2025 07:56:09 -0500 Subject: [PATCH 14/14] Added comment to explain the query length multiplier in the score for a partial or exact match --- src/Core/Package.vala | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Core/Package.vala b/src/Core/Package.vala index b639a20c1..296106453 100644 --- a/src/Core/Package.vala +++ b/src/Core/Package.vala @@ -605,8 +605,15 @@ public class AppCenterCore.Package : Object { var name_down = component.name.down (); var query_down = query.down (); - // Give extra score value if query is a substring - // or if it matches exactly the component name or id + /* + * Give extra score value if query is a substring, or if it + * matches exactly the component name or id. + * We multiply both by queries.length to negate the dilution made + * by cached_search_score when dividing by queries.length, thus + * making it a perfect EXACT_MATCH_SCORE or PARTIAL_MATCH_SCORE + * search value, since an exact or partial match should achieve + * the perfect score in any query token. + */ if (query_down == name_down || query_down == id_down) { query_score = EXACT_MATCH_SCORE * queries.length; } else if (