[gnome-software] Fix overwriting the search match value
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Fix overwriting the search match value
- Date: Mon, 29 Feb 2016 12:36:52 +0000 (UTC)
commit 413e517e0e3b252250c6873d52261302cd322aa2
Author: Richard Hughes <richard hughsie com>
Date: Mon Feb 29 12:35:00 2016 +0000
Fix overwriting the search match value
By not overwriting this field on each search we would show the wrong search
ordering when performing multiple searches where the second set of results
contained a subset of results from the first.
Also, move the match value to a new uint property rather tha trying to stuff it
in as a metadata item.
src/gs-app.c | 27 +++++++++++++++------------
src/gs-app.h | 4 ++--
src/gs-shell-search.c | 2 +-
src/plugins/gs-plugin-appstream.c | 2 +-
4 files changed, 19 insertions(+), 16 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 6ea0d82..1d3e30b 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -82,6 +82,7 @@ struct _GsApp
gchar *update_details;
AsUrgencyKind update_urgency;
gchar *management_plugin;
+ guint match_value;
gint rating;
GArray *review_ratings;
GPtrArray *reviews; /* of GsReview */
@@ -202,6 +203,10 @@ gs_app_to_string (GsApp *app)
g_string_append_printf (str, "\ticon-filename:\t%s\n",
as_icon_get_filename (app->icon));
}
+ if (app->match_value != 0) {
+ g_string_append_printf (str, "\tmatch-value:\t%05x\n",
+ app->match_value);
+ }
if (app->version != NULL)
g_string_append_printf (str, "\tversion:\t%s\n", app->version);
if (app->version_ui != NULL)
@@ -2077,6 +2082,8 @@ gs_app_subsume (GsApp *app, GsApp *other)
gs_app_set_name (app, other->name_quality, other->name);
if (other->summary != NULL)
gs_app_set_summary (app, other->summary_quality, other->summary);
+ if (other->match_value != 0)
+ gs_app_set_match_value (app, other->match_value);
if (other->description != NULL)
gs_app_set_description (app, other->description_quality, other->description);
if (other->update_details != NULL)
@@ -2121,27 +2128,23 @@ gs_app_subsume (GsApp *app, GsApp *other)
}
/**
- * gs_app_set_search_sort_key:
+ * gs_app_set_match_value:
*/
void
-gs_app_set_search_sort_key (GsApp *app, guint match_value)
+gs_app_set_match_value (GsApp *app, guint match_value)
{
- gchar md_value[6];
-
g_return_if_fail (GS_IS_APP (app));
-
- g_snprintf (md_value, sizeof(md_value), "%05x", match_value);
- gs_app_set_metadata (app, "SearchMatch", md_value);
+ app->match_value = match_value;
}
/**
- * gs_app_get_search_sort_key:
+ * gs_app_get_match_value:
*/
-const gchar *
-gs_app_get_search_sort_key (GsApp *app)
+guint
+gs_app_get_match_value (GsApp *app)
{
- g_return_val_if_fail (GS_IS_APP (app), NULL);
- return gs_app_get_metadata_item (app, "SearchMatch");
+ g_return_val_if_fail (GS_IS_APP (app), 0);
+ return app->match_value;
}
/**
diff --git a/src/gs-app.h b/src/gs-app.h
index 9f805da..97e2c4b 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -224,9 +224,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,
+void gs_app_set_match_value (GsApp *app,
guint match_value);
-const gchar *gs_app_get_search_sort_key (GsApp *app);
+guint gs_app_get_match_value (GsApp *app);
gboolean gs_app_has_quirk (GsApp *app,
AsAppQuirk quirk);
diff --git a/src/gs-shell-search.c b/src/gs-shell-search.c
index fd6f70e..f259d0c 100644
--- a/src/gs-shell-search.c
+++ b/src/gs-shell-search.c
@@ -265,7 +265,7 @@ gs_shell_search_get_app_sort_key (GsApp *app)
g_string_append_printf (key, "%c:", desc != NULL ? '2' : '1');
/* sort by the search key */
- g_string_append_printf (key, "%s:", gs_app_get_search_sort_key (app));
+ g_string_append_printf (key, "%05x:", gs_app_get_match_value (app));
/* sort by kudos */
g_string_append_printf (key, "%03i:", gs_app_get_kudos_percentage (app));
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 8fec2fd..4f47533 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -474,7 +474,7 @@ gs_plugin_add_search_item (GsPlugin *plugin,
app = gs_app_new (as_app_get_id (item));
if (!gs_appstream_refine_app (plugin, app, item, error))
return FALSE;
- gs_app_set_search_sort_key (app, match_value);
+ gs_app_set_match_value (app, match_value);
gs_plugin_add_app (list, app);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]