[tracker/fts4: 8/17] libtracker-data: Cope with ontology changes in the FTS table



commit 0074c2fadd045177e0a4a2c1193a4daf27fd137f
Author: Carlos Garnacho <carlos lanedo com>
Date:   Mon Nov 7 14:49:36 2011 +0100

    libtracker-data: Cope with ontology changes in the FTS table
    
    If a new property is with tracker:fulltextIndexed, we need to add
    a new column for it in the FTS table.

 src/libtracker-data/tracker-data-manager.c        |   19 +++++++++++++++++--
 src/libtracker-data/tracker-db-interface-sqlite.c |   10 ++++++++++
 src/libtracker-data/tracker-db-interface-sqlite.h |    3 +++
 3 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 8c88689..95faf58 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3595,7 +3595,7 @@ compare_fts_property_ids (gconstpointer a,
 }
 
 static const gchar **
-ontology_get_fts_properties (void)
+ontology_get_fts_properties (gboolean only_new)
 {
 	TrackerProperty **properties;
 	GList *fts_props = NULL, *l;
@@ -3605,6 +3605,10 @@ ontology_get_fts_properties (void)
 	properties = tracker_ontologies_get_properties (&len);
 
 	for (i = 0; i < len; i++) {
+		if (only_new && !tracker_property_get_is_new (properties[i])) {
+			continue;
+		}
+
 		if (tracker_property_get_fulltext_indexed (properties[i])) {
 			/* Sort them by ID */
 			fts_props =
@@ -3891,7 +3895,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 			return FALSE;
 		}
 
-		fts_props = ontology_get_fts_properties ();
+		fts_props = ontology_get_fts_properties (FALSE);
 		/* This is a no-op when FTS is disabled */
 		tracker_db_interface_sqlite_fts_init (iface, fts_props, TRUE);
 		g_free (fts_props);
@@ -4333,6 +4337,17 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 			}
 
 			if (update_nao) {
+#if HAVE_TRACKER_FTS
+				const gchar **new_fts_properties;
+
+				new_fts_properties = ontology_get_fts_properties (TRUE);
+
+				if (new_fts_properties) {
+					tracker_db_interface_sqlite_fts_alter_table (iface, new_fts_properties, NULL);
+					g_free (new_fts_properties);
+				}
+#endif
+
 				/* Update the nao:lastModified in the database */
 				stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &n_error,
 				        "UPDATE \"rdfs:Resource\" SET \"nao:lastModified\"= ? "
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index 5c2c42a..a55f8ea 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -1000,6 +1000,16 @@ tracker_db_interface_sqlite_fts_init (TrackerDBInterface  *db_interface,
 }
 
 #if HAVE_TRACKER_FTS
+void
+tracker_db_interface_sqlite_fts_alter_table (TrackerDBInterface  *db_interface,
+					     const gchar        **added_columns,
+					     const gchar        **removed_columns)
+{
+	if (!tracker_fts_alter_table (db_interface->db, "fts", added_columns, removed_columns)) {
+		g_critical ("Failed to update FTS columns");
+	}
+}
+
 int
 tracker_db_interface_sqlite_fts_update_init (TrackerDBInterface *db_interface,
                                              int                 id)
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.h b/src/libtracker-data/tracker-db-interface-sqlite.h
index 44c4232..6d825b1 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.h
+++ b/src/libtracker-data/tracker-db-interface-sqlite.h
@@ -48,6 +48,9 @@ void                tracker_db_interface_sqlite_wal_hook               (TrackerD
                                                                         TrackerDBWalCallback      callback);
 
 #if HAVE_TRACKER_FTS
+void                tracker_db_interface_sqlite_fts_alter_table        (TrackerDBInterface       *interface,
+                                                                        const gchar             **added_columns,
+                                                                        const gchar             **removed_columns);
 int                 tracker_db_interface_sqlite_fts_update_init        (TrackerDBInterface       *interface,
                                                                         int                       id);
 int                 tracker_db_interface_sqlite_fts_update_text        (TrackerDBInterface       *interface,



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