[gnome-software] Do not add multiple search results for the same app
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Do not add multiple search results for the same app
- Date: Wed, 24 Feb 2016 17:52:31 +0000 (UTC)
commit 6f3b0431fc8d54c3a640ec6e38d60276acd5beb2
Author: Richard Hughes <richard hughsie com>
Date: Wed Feb 24 17:48:49 2016 +0000
Do not add multiple search results for the same app
This happens when the addon also matches the search and we were choosing the
addon in preference to the main application which obviously had a lower search
score. This lead to nonsensical results when typing exact application names in
the search bar.
Now the result of the search function is a bitfield we can easily 'or' them
together and get a same value which works for all search terms.
src/plugins/gs-plugin-appstream.c | 70 +++++++++---------------------------
1 files changed, 18 insertions(+), 52 deletions(-)
---
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index a1aa094..f1e063a 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -961,74 +961,40 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
}
/**
- * gs_plugin_add_search_item_add:
- */
-static gboolean
-gs_plugin_add_search_item_add (GsPlugin *plugin,
- GList **list,
- AsApp *item,
- guint match_value,
- GError **error)
-{
- g_autoptr(GsApp) app = NULL;
- app = gs_app_new (as_app_get_id (item));
- if (!gs_plugin_refine_item (plugin, app, item, error))
- return FALSE;
- gs_app_set_search_sort_key (app, match_value);
- gs_plugin_add_app (list, app);
- return TRUE;
-}
-
-/**
* gs_plugin_add_search_item:
*/
static gboolean
gs_plugin_add_search_item (GsPlugin *plugin,
GList **list,
- AsApp *app,
+ AsApp *item,
gchar **values,
GCancellable *cancellable,
GError **error)
{
- AsApp *item;
- GPtrArray *extends;
- const gchar *id;
- gboolean ret = TRUE;
+ AsApp *item_tmp;
+ GPtrArray *addons;
guint i;
guint match_value;
+ g_autoptr(GsApp) app = NULL;
+
+ /* match against the app or any of the addons */
+ match_value = as_app_search_matches_all (item, values);
+ addons = as_app_get_addons (item);
+ for (i = 0; i < addons->len; i++) {
+ item_tmp = g_ptr_array_index (addons, i);
+ match_value |= as_app_search_matches_all (item_tmp, values);
+ }
/* no match */
- match_value = as_app_search_matches_all (app, values);
if (match_value == 0)
return TRUE;
- /* if the app does not extend an application, then just add it */
- extends = as_app_get_extends (app);
- if (extends->len == 0) {
- return gs_plugin_add_search_item_add (plugin,
- list,
- app,
- match_value,
- error);
- }
-
- /* add the thing that we extend, not the addon itself */
- for (i = 0; i < extends->len; i++) {
- if (g_cancellable_set_error_if_cancelled (cancellable, error))
- return FALSE;
-
- id = g_ptr_array_index (extends, i);
- item = as_store_get_app_by_id (plugin->priv->store, id);
- if (item == NULL)
- continue;
- ret = gs_plugin_add_search_item_add (plugin,
- list,
- item,
- match_value,
- error);
- if (!ret)
- return FALSE;
- }
+ /* create app */
+ app = gs_app_new (as_app_get_id (item));
+ if (!gs_plugin_refine_item (plugin, app, item, error))
+ return FALSE;
+ gs_app_set_search_sort_key (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]