app-system: Consider usage frequency in search results
Application search results are internally categorized in four sets, multiple and single prefix matches and multiple and single substring matches. Each set is currently sorted alphabetically by application name when concatenating the sets to the final result. Change the last step to sort each set by usage frequency instead, which is more likely to favor the most relevant match than "arbitrary" alphabetic order. https://bugzilla.gnome.org/show_bug.cgi?id=623372
This commit is contained in:
@ -528,6 +528,45 @@ shell_app_usage_get_most_used (ShellAppUsage *self,
|
||||
return apps;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* shell_app_usage_compare:
|
||||
* @self: the usage instance to request
|
||||
* @context: Activity identifier
|
||||
* @app_a: First app
|
||||
* @app_b: Second app
|
||||
*
|
||||
* Compare @app_a and @app_b based on frequency of use.
|
||||
*
|
||||
* Returns: -1 if @app_a ranks higher than @app_b, 1 if @app_b ranks higher
|
||||
* than @app_a, and 0 if both rank equally.
|
||||
*/
|
||||
int
|
||||
shell_app_usage_compare (ShellAppUsage *self,
|
||||
const char *context,
|
||||
ShellApp *app_a,
|
||||
ShellApp *app_b)
|
||||
{
|
||||
GHashTable *usages;
|
||||
UsageData *usage_a, *usage_b;
|
||||
|
||||
usages = g_hash_table_lookup (self->app_usages_for_context, context);
|
||||
if (usages == NULL)
|
||||
return 0;
|
||||
|
||||
usage_a = g_hash_table_lookup (usages, shell_app_get_id (app_a));
|
||||
usage_b = g_hash_table_lookup (usages, shell_app_get_id (app_b));
|
||||
|
||||
if (usage_a == NULL && usage_b == NULL)
|
||||
return 0;
|
||||
else if (usage_a == NULL)
|
||||
return 1;
|
||||
else if (usage_b == NULL)
|
||||
return -1;
|
||||
|
||||
return usage_b->score - usage_a->score;
|
||||
}
|
||||
|
||||
static void
|
||||
ensure_queued_save (ShellAppUsage *self)
|
||||
{
|
||||
|
Reference in New Issue
Block a user