[gnome-software] Sort by the search match value when displaying multiple apps
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Sort by the search match value when displaying multiple apps
- Date: Fri, 22 Aug 2014 13:45:31 +0000 (UTC)
commit cb2a10e67a12ac2190f50e762ee25e0a276b6058
Author: Richard Hughes <richard hughsie com>
Date: Fri Aug 22 14:44:18 2014 +0100
Sort by the search match value when displaying multiple apps
src/gs-app.c | 20 ++++++++++++++++++++
src/gs-app.h | 3 +++
src/gs-shell-search.c | 7 +++++--
src/plugins/gs-plugin-appstream.c | 5 ++++-
4 files changed, 32 insertions(+), 3 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index f594753..0569a64 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -1789,6 +1789,26 @@ gs_app_subsume (GsApp *app, GsApp *other)
}
/**
+ * gs_app_set_search_sort_key:
+ */
+void
+gs_app_set_search_sort_key (GsApp *app, guint match_value)
+{
+ gchar md_value[4];
+ g_snprintf (md_value, 4, "%03i", match_value);
+ gs_app_set_metadata (app, "SearchMatch", md_value);
+}
+
+/**
+ * gs_app_get_search_sort_key:
+ */
+const gchar *
+gs_app_get_search_sort_key (GsApp *app)
+{
+ return gs_app_get_metadata_item (app, "SearchMatch");
+}
+
+/**
* gs_app_get_property:
*/
static void
diff --git a/src/gs-app.h b/src/gs-app.h
index 36ab2a6..59575b8 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -250,6 +250,9 @@ guint gs_app_get_kudos_percentage (GsApp *app);
gboolean gs_app_get_to_be_installed (GsApp *app);
void gs_app_set_to_be_installed (GsApp *app,
gboolean to_be_installed);
+void gs_app_set_search_sort_key (GsApp *app,
+ guint match_value);
+const gchar *gs_app_get_search_sort_key (GsApp *app);
G_END_DECLS
diff --git a/src/gs-shell-search.c b/src/gs-shell-search.c
index 6c45b01..12420b9 100644
--- a/src/gs-shell-search.c
+++ b/src/gs-shell-search.c
@@ -373,8 +373,11 @@ gs_shell_search_get_app_sort_key (GsApp *app)
desc = gs_app_get_description (app);
g_string_append_printf (key, "%c:", desc != NULL ? '2' : '1');
- /* sort by rating */
- rating = gs_app_get_rating (app);
+ /* sort by the search key */
+ g_string_append_printf (key, "%s:", gs_app_get_search_sort_key (app));
+
+ /* sort by kudos */
+ rating = gs_app_get_kudos_weight (app);
g_string_append_printf (key, "%03i:", rating > 0 ? rating : 0);
/* sort by length of description */
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index d3bb30a..1f87db2 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -784,6 +784,7 @@ gs_plugin_add_search (GsPlugin *plugin,
GPtrArray *array;
GsApp *app;
guint i;
+ guint match_value;
/* load XML files */
if (g_once_init_enter (&plugin->priv->done_init)) {
@@ -798,11 +799,13 @@ gs_plugin_add_search (GsPlugin *plugin,
array = as_store_get_apps (plugin->priv->store);
for (i = 0; i < array->len; i++) {
item = g_ptr_array_index (array, i);
- if (as_app_search_matches_all (item, values) != 0) {
+ match_value = as_app_search_matches_all (item, values);
+ if (match_value != 0) {
app = gs_app_new (as_app_get_id_full (item));
ret = gs_plugin_refine_item (plugin, app, item, error);
if (!ret)
goto out;
+ gs_app_set_search_sort_key (app, match_value);
gs_plugin_add_app (list, app);
g_object_unref (app);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]