tracker r2533 - in trunk: . src/libtracker-data src/tracker-indexer
- From: ifrade svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2533 - in trunk: . src/libtracker-data src/tracker-indexer
- Date: Thu, 20 Nov 2008 13:43:58 +0000 (UTC)
Author: ifrade
Date: Thu Nov 20 13:43:58 2008
New Revision: 2533
URL: http://svn.gnome.org/viewvc/tracker?rev=2533&view=rev
Log:
Handling correctly the metadata coming from the extractor with default values when updating a file
Modified:
trunk/ChangeLog
trunk/src/libtracker-data/tracker-data-query.c
trunk/src/libtracker-data/tracker-data-query.h
trunk/src/tracker-indexer/tracker-indexer.c
Modified: trunk/src/libtracker-data/tracker-data-query.c
==============================================================================
--- trunk/src/libtracker-data/tracker-data-query.c (original)
+++ trunk/src/libtracker-data/tracker-data-query.c Thu Nov 20 13:43:58 2008
@@ -137,7 +137,12 @@
return result;
}
- result_set = tracker_data_manager_exec_proc (iface, "GetAllMetadata", service_id, service_id, service_id, NULL);
+ result_set = tracker_data_manager_exec_proc (iface,
+ "GetAllMetadata",
+ service_id,
+ service_id,
+ service_id,
+ NULL);
if (result_set) {
db_result_set_to_ptr_array (result_set, &result);
@@ -383,13 +388,16 @@
static void
result_set_to_metadata (TrackerDBResultSet *result_set,
TrackerDataMetadata *metadata,
- gboolean only_embedded)
+ gboolean embedded,
+ gboolean non_embedded)
{
TrackerField *field;
gint numeric_value;
gint metadata_id;
gboolean valid = TRUE;
+ g_return_if_fail (non_embedded || embedded);
+
while (valid) {
GValue transform = {0, };
GValue value = {0, };
@@ -421,7 +429,8 @@
return;
}
- if (tracker_field_get_embedded (field) || !only_embedded) {
+ if ((tracker_field_get_embedded (field) && embedded)
+ || !tracker_field_get_embedded (field) && non_embedded) {
if (tracker_field_get_multiple_values (field)) {
GList *new_values;
const GList *old_values;
@@ -474,7 +483,40 @@
service_id_str,
service_id_str, NULL);
if (result_set) {
- result_set_to_metadata (result_set, metadata, TRUE);
+ result_set_to_metadata (result_set, metadata, TRUE, FALSE);
+ g_object_unref (result_set);
+ }
+
+ g_free (service_id_str);
+
+ return metadata;
+}
+
+TrackerDataMetadata *
+tracker_data_query_non_embedded_metadata (TrackerService *service,
+ guint32 service_id)
+{
+ TrackerDBInterface *iface;
+ TrackerDBResultSet *result_set = NULL;
+ gchar *service_id_str;
+ TrackerDataMetadata *metadata;
+
+ metadata = tracker_data_metadata_new ();
+
+ g_return_val_if_fail (TRACKER_IS_SERVICE (service), metadata);
+
+ service_id_str = g_strdup_printf ("%d", service_id);
+ iface = tracker_db_manager_get_db_interface_by_type (tracker_service_get_name (service),
+ TRACKER_DB_CONTENT_TYPE_METADATA);
+
+
+ result_set = tracker_data_manager_exec_proc (iface,
+ "GetAllMetadata",
+ service_id_str,
+ service_id_str,
+ service_id_str, NULL);
+ if (result_set) {
+ result_set_to_metadata (result_set, metadata, FALSE, TRUE);
g_object_unref (result_set);
}
Modified: trunk/src/libtracker-data/tracker-data-query.h
==============================================================================
--- trunk/src/libtracker-data/tracker-data-query.h (original)
+++ trunk/src/libtracker-data/tracker-data-query.h Thu Nov 20 13:43:58 2008
@@ -52,6 +52,8 @@
gchar **fields);
TrackerDataMetadata *tracker_data_query_embedded_metadata (TrackerService *service,
guint32 service_id);
+TrackerDataMetadata *tracker_data_query_non_embedded_metadata (TrackerService *service,
+ guint32 service_id);
gchar * tracker_data_query_parsed_metadata (TrackerService *service,
guint32 service_id);
gchar * tracker_data_query_unparsed_metadata (TrackerService *service,
Modified: trunk/src/tracker-indexer/tracker-indexer.c
==============================================================================
--- trunk/src/tracker-indexer/tracker-indexer.c (original)
+++ trunk/src/tracker-indexer/tracker-indexer.c Thu Nov 20 13:43:58 2008
@@ -1297,6 +1297,26 @@
g_hash_table_unref (new_words);
}
+static gboolean
+remove_existing_non_emb_metadata (TrackerField *field,
+ gpointer value,
+ gpointer user_data)
+{
+ TrackerDataMetadata *old_metadata = (TrackerDataMetadata *)user_data;
+ const gchar *name;
+
+ if (tracker_field_get_embedded (field)) {
+ return FALSE;
+ }
+
+ name = tracker_field_get_name (field);
+ if (tracker_field_get_multiple_values (field)) {
+ return (tracker_data_metadata_lookup_values (old_metadata, name) != NULL);
+ } else {
+ return (tracker_data_metadata_lookup (old_metadata, name) != NULL);
+ }
+}
+
static void
item_add_or_update (TrackerIndexer *indexer,
PathInfo *info,
@@ -1324,7 +1344,7 @@
}
if (tracker_data_query_service_exists (service, dirname, basename, &id, NULL)) {
- TrackerDataMetadata *old_metadata;
+ TrackerDataMetadata *old_metadata_emb, *old_metadata_non_emb;
gchar *old_text;
gchar *new_text;
@@ -1334,11 +1354,23 @@
basename);
/*
- * Using DB directly: get old (embedded) metadata,
- * unindex, index the new metadata
+ * "metadata" (new metadata) contains embedded props and can contain
+ * non-embedded properties with default values! Dont overwrite those
+ * in the DB if they already has a value.
+ *
+ * 1) Remove all old embedded metadata from index and DB
+ * 2) Remove from new metadata all non embedded properties that already have value.
+ * 3) Save the remain new metadata.
*/
- old_metadata = tracker_data_query_embedded_metadata (service, id);
- unindex_metadata (indexer, id, service, old_metadata);
+ old_metadata_emb = tracker_data_query_embedded_metadata (service, id);
+ old_metadata_non_emb = tracker_data_query_non_embedded_metadata (service, id);
+
+ unindex_metadata (indexer, id, service, old_metadata_emb);
+
+ tracker_data_metadata_foreach_remove (metadata,
+ remove_existing_non_emb_metadata,
+ old_metadata_non_emb);
+
index_metadata (indexer, id, service, metadata);
/* Take the old text -> the new one, calculate
@@ -1350,7 +1382,8 @@
item_update_content (indexer, service, id, old_text, new_text);
g_free (old_text);
g_free (new_text);
- tracker_data_metadata_free (old_metadata);
+ tracker_data_metadata_free (old_metadata_emb);
+ tracker_data_metadata_free (old_metadata_non_emb);
return;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]