[gnome-software/1672-gnome-software-show-details-does-not-open-its-own-details-page] gs-plugin-loader: Do not pre-tokenize search term



commit 979d1edf63c9a09effd7e31374e04fef582342a7
Author: Milan Crha <mcrha redhat com>
Date:   Tue Mar 8 11:43:18 2022 +0100

    gs-plugin-loader: Do not pre-tokenize search term
    
    Let respective search plugins tokenize the user-entered string on
    their own, if needed. This helps to provide more accurate results.

 lib/gs-plugin-loader.c       | 18 ++----------------
 plugins/dummy/gs-self-test.c |  5 +++--
 2 files changed, 5 insertions(+), 18 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 4bb4731e1..127484fbc 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -11,7 +11,6 @@
 
 #include <locale.h>
 #include <glib/gi18n.h>
-#include <appstream.h>
 #include <math.h>
 
 #ifdef HAVE_SYSPROF
@@ -46,7 +45,6 @@ struct _GsPluginLoader
        gboolean                 plugin_dir_dirty;
        GPtrArray               *file_monitors;
        GsPluginStatus           global_status_last;
-       AsPool                  *as_pool;
 
        GMutex                   pending_apps_mutex;
        GPtrArray               *pending_apps;
@@ -2667,7 +2665,6 @@ gs_plugin_loader_finalize (GObject *object)
        g_ptr_array_unref (plugin_loader->file_monitors);
        g_hash_table_unref (plugin_loader->events_by_id);
        g_hash_table_unref (plugin_loader->disallow_updates);
-       g_clear_object (&plugin_loader->as_pool);
 
        g_mutex_clear (&plugin_loader->pending_apps_mutex);
        g_mutex_clear (&plugin_loader->events_by_id_mutex);
@@ -3831,21 +3828,10 @@ gs_plugin_loader_job_process_async (GsPluginLoader *plugin_loader,
        g_task_set_check_cancellable (task, FALSE);
        g_task_set_return_on_cancel (task, FALSE);
 
-       /* AppStream metadata pool, we only need it to create good search tokens */
-       if (plugin_loader->as_pool == NULL)
-               plugin_loader->as_pool = as_pool_new ();
-
-       /* pre-tokenize search */
        if (action == GS_PLUGIN_ACTION_SEARCH) {
                const gchar *search = gs_plugin_job_get_search (plugin_job);
-               helper->tokens = as_pool_build_search_tokens (plugin_loader->as_pool, search);
-               if (helper->tokens == NULL) {
-                       g_task_return_new_error (task,
-                                                GS_PLUGIN_ERROR,
-                                                GS_PLUGIN_ERROR_NOT_SUPPORTED,
-                                                "failed to tokenize %s", search);
-                       return;
-               }
+               helper->tokens = g_new0 (gchar *, 2);
+               helper->tokens[0] = g_strdup (search);
        }
 
        /* jobs always have a valid cancellable, so proxy the caller */
diff --git a/plugins/dummy/gs-self-test.c b/plugins/dummy/gs-self-test.c
index 9964f166c..e730eca36 100644
--- a/plugins/dummy/gs-self-test.c
+++ b/plugins/dummy/gs-self-test.c
@@ -510,8 +510,9 @@ gs_plugins_dummy_search_invalid_func (GsPluginLoader *plugin_loader)
                                         NULL);
        list = gs_plugin_loader_job_process (plugin_loader, plugin_job, NULL, &error);
        gs_test_flush_main_context ();
-       g_assert_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_NOT_SUPPORTED);
-       g_assert (list == NULL);
+       g_assert_no_error (error);
+       g_assert_nonnull (list);
+       g_assert_cmpint (gs_app_list_length (list), ==, 0);
 }
 
 static void


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