diff options
-rw-r--r-- | libappstream-glib/as-app-private.h | 3 | ||||
-rw-r--r-- | libappstream-glib/as-app.c | 25 | ||||
-rw-r--r-- | libappstream-glib/as-stemmer.c | 11 | ||||
-rw-r--r-- | libappstream-glib/as-store.c | 7 |
4 files changed, 33 insertions, 13 deletions
diff --git a/libappstream-glib/as-app-private.h b/libappstream-glib/as-app-private.h index 5637479..6d47214 100644 --- a/libappstream-glib/as-app-private.h +++ b/libappstream-glib/as-app-private.h @@ -30,6 +30,7 @@ #include "as-app.h" #include "as-node-private.h" +#include "as-stemmer.h" G_BEGIN_DECLS @@ -112,6 +113,8 @@ gboolean as_app_parse_inf_file (AsApp *app, const gchar *filename, AsAppParseFlags flags, GError **error); +void as_app_set_stemmer (AsApp *app, + AsStemmer *stemmer); G_END_DECLS diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c index 0fd3dfc..a3f2b6e 100644 --- a/libappstream-glib/as-app.c +++ b/libappstream-glib/as-app.c @@ -466,6 +466,9 @@ as_app_finalize (GObject *object) AsApp *app = AS_APP (object); AsAppPrivate *priv = GET_PRIVATE (app); + if (priv->stemmer != NULL) + g_object_unref (priv->stemmer); + g_free (priv->icon_path); g_free (priv->id_filename); g_free (priv->id); @@ -487,7 +490,6 @@ as_app_finalize (GObject *object) g_hash_table_unref (priv->names); g_hash_table_unref (priv->urls); g_hash_table_unref (priv->token_cache); - g_object_unref (priv->stemmer); g_ptr_array_unref (priv->addons); g_ptr_array_unref (priv->categories); g_ptr_array_unref (priv->compulsory_for_desktops); @@ -515,7 +517,6 @@ static void as_app_init (AsApp *app) { AsAppPrivate *priv = GET_PRIVATE (app); - priv->stemmer = as_stemmer_new (); priv->categories = g_ptr_array_new_with_free_func (g_free); priv->compulsory_for_desktops = g_ptr_array_new_with_free_func (g_free); priv->content_ratings = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); @@ -5095,7 +5096,10 @@ as_app_add_token_internal (AsApp *app, return; /* does the token already exist */ - value_stem = as_stemmer_process (priv->stemmer, value); + if (priv->stemmer != NULL) + value_stem = as_stemmer_process (priv->stemmer, value); + if (value_stem == NULL) + value_stem = g_strdup (value); match_pval = g_hash_table_lookup (priv->token_cache, value_stem); if (match_pval != NULL) { *match_pval |= match_flag; @@ -5275,7 +5279,10 @@ as_app_search_matches (AsApp *app, const gchar *search) return 0; /* find the exact match (which is more awesome than a partial match) */ - search_stem = as_stemmer_process (priv->stemmer, search); + if (priv->stemmer != NULL) + search_stem = as_stemmer_process (priv->stemmer, search); + if (search_stem == NULL) + search_stem = g_strdup (search); match_pval = g_hash_table_lookup (priv->token_cache, search_stem); if (match_pval != NULL) return (guint) *match_pval << 2; @@ -5859,6 +5866,16 @@ as_app_remove_veto (AsApp *app, const gchar *description) } /** + * as_app_set_stemmer: (skip) + **/ +void +as_app_set_stemmer (AsApp *app, AsStemmer *stemmer) +{ + AsAppPrivate *priv = GET_PRIVATE (app); + g_set_object (&priv->stemmer, stemmer); +} + +/** * as_app_new: * * Creates a new #AsApp. diff --git a/libappstream-glib/as-stemmer.c b/libappstream-glib/as-stemmer.c index b3505dd..b5017ad 100644 --- a/libappstream-glib/as-stemmer.c +++ b/libappstream-glib/as-stemmer.c @@ -39,8 +39,6 @@ struct _AsStemmer G_DEFINE_TYPE (AsStemmer, as_stemmer, G_TYPE_OBJECT) -static gpointer as_stemmer_object = NULL; - /** * as_stemmer_process: * @stemmer: A #AsStemmer @@ -112,11 +110,6 @@ as_stemmer_init (AsStemmer *stemmer) AsStemmer * as_stemmer_new (void) { - if (as_stemmer_object != NULL) { - g_object_ref (as_stemmer_object); - } else { - as_stemmer_object = g_object_new (AS_TYPE_STEMMER, NULL); - g_object_add_weak_pointer (as_stemmer_object, &as_stemmer_object); - } - return AS_STEMMER (as_stemmer_object); + AsStemmer *stemmer = g_object_new (AS_TYPE_STEMMER, NULL); + return AS_STEMMER (stemmer); } diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c index 62b219f..42096ef 100644 --- a/libappstream-glib/as-store.c +++ b/libappstream-glib/as-store.c @@ -41,6 +41,7 @@ #include "as-problem.h" #include "as-profile.h" #include "as-monitor.h" +#include "as-stemmer.h" #include "as-store.h" #include "as-utils-private.h" #include "as-yaml.h" @@ -78,6 +79,7 @@ typedef struct guint changed_block_refcnt; gboolean is_pending_changed_signal; AsProfile *profile; + AsStemmer *stemmer; } AsStorePrivate; typedef struct { @@ -129,6 +131,7 @@ as_store_finalize (GObject *object) g_ptr_array_unref (priv->array); g_object_unref (priv->monitor); g_object_unref (priv->profile); + g_object_unref (priv->stemmer); g_hash_table_unref (priv->hash_id); g_hash_table_unref (priv->hash_merge_id); g_hash_table_unref (priv->hash_unique_id); @@ -1215,6 +1218,9 @@ as_store_add_app (AsStore *store, AsApp *app) g_object_ref (app)); } + /* add helper objects */ + as_app_set_stemmer (app, priv->stemmer); + /* added */ g_signal_emit (store, signals[SIGNAL_APP_ADDED], 0, app); as_store_perhaps_emit_changed (store, "add-app"); @@ -3297,6 +3303,7 @@ as_store_init (AsStore *store) { AsStorePrivate *priv = GET_PRIVATE (store); priv->profile = as_profile_new (); + priv->stemmer = as_stemmer_new (); priv->api_version = AS_API_VERSION_NEWEST; priv->array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); priv->watch_flags = AS_STORE_WATCH_FLAG_NONE; |