tracker r2586 - in branches/turtle: . src/libtracker-data src/tracker-indexer
- From: pvanhoof svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2586 - in branches/turtle: . src/libtracker-data src/tracker-indexer
- Date: Thu, 27 Nov 2008 10:43:11 +0000 (UTC)
Author: pvanhoof
Date: Thu Nov 27 10:43:10 2008
New Revision: 2586
URL: http://svn.gnome.org/viewvc/tracker?rev=2586&view=rev
Log:
2008-11-27 Philip Van Hoof <philip codeminded be>
* src/tracker-indexer/tracker-removable-device.c
* src/libtracker-data/tracker-data-update.c
* src/libtracker-data/tracker-data-update.h: Implemented removing
a resource. Backported storing a resource from the decomposed
tables -branch.
Modified:
branches/turtle/ChangeLog
branches/turtle/src/libtracker-data/tracker-data-update.c
branches/turtle/src/libtracker-data/tracker-data-update.h
branches/turtle/src/tracker-indexer/tracker-removable-device.c
Modified: branches/turtle/src/libtracker-data/tracker-data-update.c
==============================================================================
--- branches/turtle/src/libtracker-data/tracker-data-update.c (original)
+++ branches/turtle/src/libtracker-data/tracker-data-update.c Thu Nov 27 10:43:10 2008
@@ -571,14 +571,168 @@
tracker_data_manager_exec (iface, "DELETE FROM Events WHERE BeingHandled = 1");
}
+/* TODO: URI branch path -> uri */
+void
+tracker_data_delete_service (const gchar *path,
+ const gchar *rdf_type)
+{
+ TrackerService *service = tracker_ontology_get_service_by_name (rdf_type);
+ const gchar *service_type = tracker_service_get_name (service);
+ guint32 service_id = tracker_data_query_file_id (service_type, path);
+
+ tracker_data_update_delete_service (service, service_id);
+ tracker_data_update_delete_service_recursively (service, (gchar *) path);
+ tracker_data_update_delete_all_metadata (service, service_id);
+}
+
+/* TODO: URI branch path -> uri */
+
+typedef struct {
+ TrackerService *service;
+ guint32 iid_value;
+ TrackerLanguage *language;
+ TrackerConfig *config;
+} ForeachInMetadataInfo;
+
+static void
+foreach_in_metadata_set_metadata(TrackerField *field,
+ gpointer value,
+ gpointer user_data)
+{
+ ForeachInMetadataInfo *info = user_data;
+ gchar *parsed_value;
+
+ parsed_value = tracker_parser_text_to_string (value,
+ info->language,
+ tracker_config_get_max_word_length (info->config),
+ tracker_config_get_min_word_length (info->config),
+ tracker_field_get_filtered (field),
+ tracker_field_get_filtered (field),
+ tracker_field_get_delimited (field));
+
+ if (!parsed_value) {
+ return;
+ }
+
+ tracker_data_update_set_metadata (info->service, info->iid_value, field, value, parsed_value);
+
+ g_free (parsed_value);
+}
+
void
-tracker_data_replace_service (const gchar *uri,
+tracker_data_replace_service (const gchar *path,
const gchar *rdf_type,
TrackerDataMetadata *metadata)
{
- /* Unimplemented in this branch of Tracker (it's implemented in JÃrg's
- * new data model, it's only here for API consistency with JÃrg's work) */
+ TrackerDBInterface *iface;
+ TrackerDBResultSet *result_set;
+ const gchar *modified;
+ GError *error = NULL;
+ TrackerService *service;
+ gchar *escaped_path;
+
+ /* TODO untested and unfinished port that came from the decomposed
+ * branch of JÃrg. */
+
+ if (!rdf_type)
+ return;
+
+ service = tracker_ontology_get_service_by_name (rdf_type);
+
+ iface = tracker_db_manager_get_db_interface_by_type (tracker_service_get_name (service),
+ TRACKER_DB_CONTENT_TYPE_METADATA);
+
+ modified = tracker_data_metadata_lookup (metadata, "File:Modified");
+
+ if (!modified) {
+ return;
+ }
+
+ escaped_path = tracker_escape_string (path);
+
+ result_set = tracker_db_interface_execute_query (iface, &error,
+ "SELECT ID, Accessed < '%s' FROM Services "
+ "WHERE Path = '%s'",
+ modified,
+ escaped_path);
+
+ if (error) {
+ #ifdef TURTLE_DEBUG
+ g_print ("Q ERROR: %s\n", error->message);
+ #endif /* TURTLE_DEBUG */
+ g_error_free (error);
+ }
+
+ if (result_set) {
+ GValue id_value = { 0, };
+ GValue is_value = { 0, };
+ gint iid_value, iis_value;
+
+ _tracker_db_result_set_get_value (result_set, 0, &id_value);
+ iid_value = g_value_get_int (&id_value);
+
+ _tracker_db_result_set_get_value (result_set, 1, &is_value);
+ iis_value = g_value_get_int (&is_value);
+
+ if (iis_value) {
+ ForeachInMetadataInfo *info = g_slice_new (ForeachInMetadataInfo);
+ info->service = service;
+ info->iid_value = iid_value;
+
+ info->config = tracker_config_new ();
+ info->language = tracker_language_new (info->config);
+
+ tracker_data_metadata_foreach (metadata,
+ foreach_in_metadata_set_metadata,
+ info);
+
+ g_object_unref (info->language);
+ g_object_unref (info->config);
+
+ g_slice_free (ForeachInMetadataInfo, info);
+ }
+
+ g_value_unset (&id_value);
+ g_value_unset (&is_value);
+
+ g_object_unref (result_set);
+
+ } else {
+ gchar *dirname;
+ const gchar *basename;
+ guint32 id;
+
+ id = tracker_data_update_get_new_service_id (iface);
+
+ basename = g_basename (path);
+ dirname = g_dirname (path);
+
+ if (tracker_data_update_create_service (service, id,
+ dirname, basename,
+ metadata)) {
+ ForeachInMetadataInfo *info;
+
+ info = g_slice_new (ForeachInMetadataInfo);
+
+ info->service = service;
+ info->iid_value = id;
+
+ info->config = tracker_config_new ();
+ info->language = tracker_language_new (info->config);
+
+ tracker_data_metadata_foreach (metadata,
+ foreach_in_metadata_set_metadata,
+ info);
+
+ g_object_unref (info->language);
+ g_object_unref (info->config);
+
+ g_slice_free (ForeachInMetadataInfo, info);
+ }
+ }
+
+ g_free (escaped_path);
}
void
Modified: branches/turtle/src/libtracker-data/tracker-data-update.h
==============================================================================
--- branches/turtle/src/libtracker-data/tracker-data-update.h (original)
+++ branches/turtle/src/libtracker-data/tracker-data-update.h Thu Nov 27 10:43:10 2008
@@ -51,9 +51,13 @@
void tracker_data_update_move_service (TrackerService *service,
const gchar *from,
const gchar *to);
-void tracker_data_replace_service (const gchar *uri,
+
+/* Turtle importing */
+void tracker_data_replace_service (const gchar *path,
const gchar *rdf_type,
TrackerDataMetadata *metadata);
+void tracker_data_delete_service (const gchar *path,
+ const gchar *rdf_type);
/* Metadata */
void tracker_data_update_set_metadata (TrackerService *service,
Modified: branches/turtle/src/tracker-indexer/tracker-removable-device.c
==============================================================================
--- branches/turtle/src/tracker-indexer/tracker-removable-device.c (original)
+++ branches/turtle/src/tracker-indexer/tracker-removable-device.c Thu Nov 27 10:43:10 2008
@@ -132,16 +132,21 @@
}
static void
-commit_turtle_parse_info_storer (TurtleStorerInfo *info, gboolean may_flush)
+commit_turtle_parse_info_storer (TurtleStorerInfo *info, gboolean may_flush, gboolean is_removal)
{
if (info->last_subject) {
/* We have it as a URI, database api wants Paths. Update this when
- * the database api becomes sane and uses URIs everywhere */
+ * the database api becomes sane and uses URIs everywhere, the
+ * '+ 7' means that we cut away the 'file://' prefix. */
- tracker_data_replace_service (info->last_subject + 7,
- info->rdf_type,
- info->metadata);
+ if (!is_removal)
+ tracker_data_replace_service (info->last_subject + 7,
+ info->rdf_type,
+ info->metadata);
+ else
+ tracker_data_delete_service (info->last_subject + 7,
+ info->rdf_type);
info->amount++;
@@ -179,8 +184,9 @@
if (!info->last_subject || strcmp (subject, info->last_subject) != 0) {
/* Commit previous subject */
+ commit_turtle_parse_info_storer (info, TRUE, FALSE);
- commit_turtle_parse_info_storer (info, TRUE);
+ /* Install next subject */
info->last_subject = g_strdup (subject);
info->metadata = tracker_data_metadata_new ();
}
@@ -205,16 +211,33 @@
} else if (triple->object_type == RAPTOR_IDENTIFIER_TYPE_RESOURCE) {
gchar *key = g_strdup_printf ("file://%s/:", info->base);
- if (strcmp (key, triple->object) == 0) {
+ if (triple->object && strcmp (key, triple->object) == 0 &&
+ triple->predicate && strcmp (key, triple->predicate) == 0)
+ {
+ /* <URI> <:> <:> - is a removal of the resource */
+
+ /* We commit this subject as a removal, the last_subject
+ * field will be cleared for the next subject to be set
+ * ready first next process loop. */
+
+ commit_turtle_parse_info_storer (info, FALSE, TRUE);
+ }
+ else
+ if (triple->object && strcmp (key, triple->object) == 0 &&
+ triple->predicate && strcmp (key, triple->predicate) != 0)
+ {
gchar *predicate;
+ /* <URI> <Pfx:Predicate> <:> - is a removal of the
+ * resource's Pfx:Predicate */
predicate = (gchar *) raptor_uri_as_string ((raptor_uri *) triple->predicate);
+ /* We put NULL here, so that a null value goes into
+ * SQLite. Perhaps we should change this? If so, Why? */
tracker_data_metadata_insert (info->metadata,
predicate,
- g_strdup (""));
-
- }
+ NULL);
+ }
g_free (key);
}
@@ -426,7 +449,7 @@
raptor_parse_file (parser, uri, base_uri);
/* Commit final subject (or loop doesn't handle the very last) */
- commit_turtle_parse_info_storer (info, FALSE);
+ commit_turtle_parse_info_storer (info, FALSE, FALSE);
/* g_timer_stop (timer);
g_print ("\nTIME: %f\n", g_timer_elapsed (timer, NULL)); */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]