[gnome-software/gnome-3-12] Sort the results by kudo for the shell sort provider



commit e6b4ec022addd07737f712e32e0f085b077eb671
Author: Richard Hughes <richard hughsie com>
Date:   Mon Apr 7 15:35:46 2014 +0100

    Sort the results by kudo for the shell sort provider
    
    Ensure results are sorted before returning results to GNOME Shell, as typically
    only 3 results are being shown. If this is not done we show the results in the
    order they are parsed, which for AppStream are the application overrides and
    distro-specific additions.
    
    We sort by the kudo rather than the rating for two reasons; the first being that
    only a few applications have been rated by end users, and the second that we get
    the kudo information 'for free' meaning we don't have to set any additional
    GsPluginRefine flags which would take longer to return to the shell.

 src/gs-shell-search-provider.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-shell-search-provider.c b/src/gs-shell-search-provider.c
index 0a53b30..438e56b 100644
--- a/src/gs-shell-search-provider.c
+++ b/src/gs-shell-search-provider.c
@@ -88,6 +88,22 @@ cancel_current_search (GsShellSearchProvider *self)
        }
 }
 
+/**
+ * search_sort_by_kudo_cb:
+ **/
+static gint
+search_sort_by_kudo_cb (gconstpointer a, gconstpointer b)
+{
+       guint pa, pb;
+       pa = gs_app_get_kudos_percentage (GS_APP (a));
+       pb = gs_app_get_kudos_percentage (GS_APP (b));
+       if (pa < pb)
+               return 1;
+       else if (pa > pb)
+               return -1;
+       return 0;
+}
+
 static void
 search_done_cb (GObject *source,
                GAsyncResult *res,
@@ -113,6 +129,9 @@ search_done_cb (GObject *source,
                return; 
        }
 
+       /* sort by kudos, as there is no ratings data by default */
+       list = g_list_sort (list, search_sort_by_kudo_cb);
+
        g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
        for (l = list; l != NULL; l = l->next) {
                GsApp *app = GS_APP (l->data);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]