[tracker/wip/fts4: 3/21] libtracker-data: Add tracker_db_interface_sqlite_fts_delete_text()



commit da42a713b5d1a3cb4bd47ead776adfdeb2cdf4fa
Author: Carlos Garnacho <carlos lanedo com>
Date:   Mon Oct 31 14:28:49 2011 +0100

    libtracker-data: Add tracker_db_interface_sqlite_fts_delete_text()
    
    This function removes from the FTS table the text from a resourceid/propid
    pair.

 src/libtracker-data/tracker-data-update.c         |   10 ++--
 src/libtracker-data/tracker-db-interface-sqlite.c |   66 +++++++++++++++++++++
 src/libtracker-data/tracker-db-interface-sqlite.h |    3 +
 3 files changed, 74 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index c8c9d7a..c09c648 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -1459,17 +1459,17 @@ get_old_property_values (TrackerProperty  *property,
 
 					if (tracker_property_get_fulltext_indexed (prop)
 					    && check_property_domain (prop)) {
+						gint prop_id;
 						gint i;
 
 						old_values = get_property_values (prop);
+						prop_id = tracker_data_query_resource_id (tracker_property_get_uri (prop));
 
 						/* delete old fts entries */
 						for (i = 0; i < old_values->n_values; i++) {
-							tracker_db_interface_sqlite_fts_update_text (iface,
-								resource_buffer->id,
-								-1,
-								g_value_get_string (g_value_array_get_nth (old_values, i)),
-								!tracker_property_get_fulltext_no_limit (prop));
+							tracker_db_interface_sqlite_fts_delete_text (iface,
+							                                             resource_buffer->id,
+							                                             prop_id);
 						}
 					}
 				}
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index fbd8d66..4888e96 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -1082,6 +1082,72 @@ tracker_db_interface_sqlite_fts_update_text (TrackerDBInterface *db_interface,
 	return TRUE;
 }
 
+gboolean
+tracker_db_interface_sqlite_fts_delete_text (TrackerDBInterface *db_interface,
+                                             int                 id,
+                                             int                 column_id)
+{
+	TrackerDBStatement *stmt;
+	GError *error = NULL;
+	int doc_id;
+
+	stmt = tracker_db_interface_create_statement (db_interface,
+	                                              TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE,
+	                                              &error,
+	                                              "DELETE FROM fts "
+	                                              "WHERE docid IN ("
+	                                              "  SELECT docid "
+	                                              "  FROM fts_prop_map "
+	                                              "  WHERE resourceid = ? AND propid = ?"
+	                                              ")");
+	if (!stmt) {
+		if (error) {
+			g_warning ("Could not delete FTS text: %s\n",
+			           error->message);
+			g_error_free (error);
+		}
+		return FALSE;
+	}
+
+	tracker_db_statement_execute (stmt, &error);
+	g_object_unref (stmt);
+
+	if (error) {
+		g_warning ("Could not execute FTS text deletion: %s", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+
+	stmt = tracker_db_interface_create_statement (db_interface,
+	                                              TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE,
+	                                              &error,
+	                                              "DELETE FROM fts "
+	                                              "WHERE docid IN ("
+	                                              "  SELECT docid "
+	                                              "  FROM fts_prop_map "
+	                                              "  WHERE resourceid = ? AND propid = ?"
+	                                              ")");
+	if (!stmt) {
+		if (error) {
+			g_warning ("Could not delete FTS property map: %s\n",
+			           error->message);
+			g_error_free (error);
+		}
+		return FALSE;
+	}
+
+	tracker_db_statement_execute (stmt, &error);
+	g_object_unref (stmt);
+
+	if (error) {
+		g_warning ("Could not execute FTS properties deletion: %s", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
 void
 tracker_db_interface_sqlite_fts_update_commit (TrackerDBInterface *db_interface)
 {
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.h b/src/libtracker-data/tracker-db-interface-sqlite.h
index bdd1b56..f31d943 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.h
+++ b/src/libtracker-data/tracker-db-interface-sqlite.h
@@ -54,6 +54,9 @@ int                 tracker_db_interface_sqlite_fts_update_text        (TrackerD
                                                                         int                       column_id,
                                                                         const char               *text,
                                                                         gboolean                  limit_word_length);
+gboolean            tracker_db_interface_sqlite_fts_delete_text        (TrackerDBInterface       *db_interface,
+									int                       id,
+									int                       column_id);
 void                tracker_db_interface_sqlite_fts_update_commit      (TrackerDBInterface       *interface);
 void                tracker_db_interface_sqlite_fts_update_rollback    (TrackerDBInterface       *interface);
 #endif



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