[tracker/wip/carlosg/domain-ontologies: 49/116] libtracker-fts: Pass TrackerDBInterface through FTS machinery



commit 946f000eb155ea3d1baefdf2a2f55931ed38fd83
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Jun 9 23:34:30 2017 +0200

    libtracker-fts: Pass TrackerDBInterface through FTS machinery
    
    It will be useful in order to retrieve the data manager, and the
    TrackerOntologies.

 src/libtracker-data/tracker-db-interface-sqlite.c |    2 +-
 src/libtracker-fts/tracker-fts-tokenizer.c        |   43 +++++++++++++++++----
 src/libtracker-fts/tracker-fts-tokenizer.h        |    6 ++-
 src/libtracker-fts/tracker-fts.c                  |    7 ++-
 src/libtracker-fts/tracker-fts.h                  |    6 ++-
 5 files changed, 48 insertions(+), 16 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c 
b/src/libtracker-data/tracker-db-interface-sqlite.c
index ff5298e..3b991ca 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -1622,7 +1622,7 @@ tracker_db_interface_sqlite_fts_init (TrackerDBInterface  *db_interface,
 #if HAVE_TRACKER_FTS
        GStrv fts_columns;
 
-       tracker_fts_init_db (db_interface->db, properties);
+       tracker_fts_init_db (db_interface->db, db_interface, properties);
 
        if (create &&
            !tracker_fts_create_table (db_interface->db, "fts5",
diff --git a/src/libtracker-fts/tracker-fts-tokenizer.c b/src/libtracker-fts/tracker-fts-tokenizer.c
index b7ddf7b..e3db10c 100644
--- a/src/libtracker-fts/tracker-fts-tokenizer.c
+++ b/src/libtracker-fts/tracker-fts-tokenizer.c
@@ -36,6 +36,7 @@
 
 typedef struct TrackerTokenizerData TrackerTokenizerData;
 typedef struct TrackerTokenizer TrackerTokenizer;
+typedef struct TrackerTokenizerFunctionData TrackerTokenizerFunctionData;
 
 struct TrackerTokenizerData {
        TrackerLanguage *language;
@@ -52,6 +53,11 @@ struct TrackerTokenizer {
        TrackerParser *parser;
 };
 
+struct TrackerTokenizerFunctionData {
+       TrackerDBInterface *interface;
+       gchar **property_names;
+};
+
 static int
 tracker_tokenizer_create (void           *data,
                           const char    **argv,
@@ -390,11 +396,32 @@ get_fts5_api (sqlite3 *db) {
        return api;
 }
 
+TrackerTokenizerFunctionData *
+tracker_tokenizer_function_data_new (TrackerDBInterface  *interface,
+                                     const gchar        **property_names)
+{
+       TrackerTokenizerFunctionData *data;
+
+       data = g_new0 (TrackerTokenizerFunctionData, 1);
+       data->interface = g_object_ref (interface);
+       data->property_names = g_strdupv (property_names);
+}
+
+static void
+tracker_tokenizer_function_data_free (TrackerTokenizerFunctionData *data)
+{
+       g_object_unref (data->interface);
+       g_strfreev (data->property_names);
+       g_free (data);
+}
+
 gboolean
-tracker_tokenizer_initialize (sqlite3      *db,
-                              const gchar **property_names)
+tracker_tokenizer_initialize (sqlite3             *db,
+                              TrackerDBInterface  *interface,
+                              const gchar        **property_names)
 {
        TrackerTokenizerData *data;
+       TrackerTokenizerFunctionData *func_data;
        fts5_tokenizer *tokenizer;
        fts5_api *api;
 
@@ -409,16 +436,16 @@ tracker_tokenizer_initialize (sqlite3      *db,
                               tracker_tokenizer_data_free);
 
        /* Offsets */
-       api->xCreateFunction (api, "tracker_offsets",
-                             g_strdupv ((gchar **) property_names),
+       func_data = tracker_tokenizer_function_data_new (interface, property_names);
+       api->xCreateFunction (api, "tracker_offsets", func_data,
                              &tracker_offsets_function,
-                             (GDestroyNotify) g_strfreev);
+                             (GDestroyNotify) tracker_tokenizer_function_data_free);
 
        /* Rank */
-       api->xCreateFunction (api, "tracker_rank",
-                             g_strdupv ((gchar **) property_names),
+       func_data = tracker_tokenizer_function_data_new (interface, property_names);
+       api->xCreateFunction (api, "tracker_rank", func_data,
                              &tracker_rank_function,
-                             (GDestroyNotify) g_strfreev);
+                             (GDestroyNotify) tracker_tokenizer_function_data_free);
 
        return TRUE;
 }
diff --git a/src/libtracker-fts/tracker-fts-tokenizer.h b/src/libtracker-fts/tracker-fts-tokenizer.h
index 30843d2..457476c 100644
--- a/src/libtracker-fts/tracker-fts-tokenizer.h
+++ b/src/libtracker-fts/tracker-fts-tokenizer.h
@@ -21,11 +21,13 @@
 
 #include <sqlite3.h>
 #include <glib.h>
+#include <libtracker-data/tracker-db-interface.h>
 
 #ifndef __TRACKER_FTS_TOKENIZER_H__
 #define __TRACKER_FTS_TOKENIZER_H__
 
-gboolean tracker_tokenizer_initialize (sqlite3      *db,
-                                       const gchar **property_names);
+gboolean tracker_tokenizer_initialize (sqlite3             *db,
+                                       TrackerDBInterface  *interface,
+                                       const gchar        **property_names);
 
 #endif /* __TRACKER_FTS_TOKENIZER_H__ */
diff --git a/src/libtracker-fts/tracker-fts.c b/src/libtracker-fts/tracker-fts.c
index 3f6e26b..ec5ac29 100644
--- a/src/libtracker-fts/tracker-fts.c
+++ b/src/libtracker-fts/tracker-fts.c
@@ -99,8 +99,9 @@ get_fts_properties (GHashTable  *tables)
 }
 
 gboolean
-tracker_fts_init_db (sqlite3    *db,
-                     GHashTable *tables)
+tracker_fts_init_db (sqlite3            *db,
+                     TrackerDBInterface *interface,
+                     GHashTable         *tables)
 {
        gchar **property_names;
        gboolean retval;
@@ -108,7 +109,7 @@ tracker_fts_init_db (sqlite3    *db,
        g_return_val_if_fail (initialized == TRUE, FALSE);
 
        property_names = get_fts_properties (tables);
-       retval = tracker_tokenizer_initialize (db, (const gchar **) property_names);
+       retval = tracker_tokenizer_initialize (db, interface, (const gchar **) property_names);
        g_strfreev (property_names);
 
        return retval;
diff --git a/src/libtracker-fts/tracker-fts.h b/src/libtracker-fts/tracker-fts.h
index 945338e..e1461f1 100644
--- a/src/libtracker-fts/tracker-fts.h
+++ b/src/libtracker-fts/tracker-fts.h
@@ -25,13 +25,15 @@
 #include <sqlite3.h>
 
 #include <glib.h>
+#include <libtracker-data/tracker-db-interface.h>
 
 G_BEGIN_DECLS
 
 gboolean    tracker_fts_init             (void);
 gboolean    tracker_fts_shutdown         (void);
-gboolean    tracker_fts_init_db          (sqlite3    *db,
-                                          GHashTable *tables);
+gboolean    tracker_fts_init_db          (sqlite3            *db,
+                                          TrackerDBInterface *interface,
+                                          GHashTable         *tables);
 gboolean    tracker_fts_create_table     (sqlite3    *db,
                                           gchar      *table_name,
                                           GHashTable *tables,


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