[tracker/tracker-store: 1/11] tracker-indexer: Experimental move to SPARQL
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker/tracker-store: 1/11] tracker-indexer: Experimental move to SPARQL
- Date: Mon, 4 May 2009 12:04:56 -0400 (EDT)
commit 14bc558e8f040220219916485d4ffef74e155f2f
Author: Jürg Billeter <j bitron ch>
Date: Wed Apr 29 16:53:11 2009 +0200
tracker-indexer: Experimental move to SPARQL
---
src/tracker-indexer/tracker-indexer.c | 63 ++++----------------
.../tracker-module-metadata-private.h | 1 +
src/tracker-indexer/tracker-module-metadata.c | 27 ++++++++
3 files changed, 41 insertions(+), 50 deletions(-)
diff --git a/src/tracker-indexer/tracker-indexer.c b/src/tracker-indexer/tracker-indexer.c
index f97fa7a..be87515 100644
--- a/src/tracker-indexer/tracker-indexer.c
+++ b/src/tracker-indexer/tracker-indexer.c
@@ -77,6 +77,8 @@
#include <libtracker-data/tracker-turtle.h>
#include <libtracker-data/tracker-data-backup.h>
+#include <libtracker/tracker.h>
+
#include "tracker-indexer.h"
#include "tracker-indexer-module.h"
#include "tracker-marshal.h"
@@ -1032,53 +1034,6 @@ add_directory (TrackerIndexer *indexer,
}
static void
-index_metadata_foreach (const gchar *subject,
- const gchar *predicate,
- const gchar *object,
- gpointer user_data)
-{
- MetadataForeachData *data;
- gint throttle;
-
- if (!object) {
- return;
- }
-
- data = (MetadataForeachData *) user_data;
-
- /* Throttle indexer, value 9 is from older code, why 9? */
- throttle = tracker_config_get_throttle (data->config);
- if (throttle > 9) {
- tracker_throttle (data->config, throttle * 100);
- }
-
- if (data->add) {
- tracker_data_insert_statement (subject, predicate, object);
- } else {
- tracker_data_delete_statement (subject, predicate, object);
- }
-}
-
-static void
-index_metadata (TrackerIndexer *indexer,
- const gchar *uri,
- guint32 id,
- TrackerModuleMetadata *metadata)
-{
- MetadataForeachData data;
-
- data.language = indexer->private->language;
- data.config = indexer->private->config;
- data.uri = uri;
- data.id = id;
- data.add = TRUE;
-
- tracker_module_metadata_foreach (metadata, index_metadata_foreach, &data);
-
- schedule_flush (indexer, FALSE);
-}
-
-static void
item_update_content (TrackerIndexer *indexer,
const gchar *uri,
guint32 id,
@@ -1167,6 +1122,7 @@ item_add_or_update (TrackerIndexer *indexer,
{
guint32 id;
gchar *mount_point = NULL;
+ gchar *sparql;
if (tracker_data_query_resource_exists (uri, &id)) {
gchar *old_text;
@@ -1193,7 +1149,11 @@ item_add_or_update (TrackerIndexer *indexer,
*/
tracker_data_delete_resource_description (uri);
- index_metadata (indexer, uri, id, metadata);
+ sparql = tracker_module_metadata_get_sparql (metadata);
+ tracker_data_update_sparql (sparql, NULL);
+ g_free (sparql);
+
+ schedule_flush (indexer, FALSE);
/* Take the old text -> the new one, calculate
* difference and add the words.
@@ -1207,9 +1167,12 @@ item_add_or_update (TrackerIndexer *indexer,
uri);
/* Service wasn't previously indexed */
- id = tracker_data_insert_resource (uri);
- index_metadata (indexer, uri, id, metadata);
+ sparql = tracker_module_metadata_get_sparql (metadata);
+ tracker_data_update_sparql (sparql, NULL);
+ g_free (sparql);
+
+ schedule_flush (indexer, FALSE);
item_add_to_datasource (indexer, uri, info->module_file, metadata);
diff --git a/src/tracker-indexer/tracker-module-metadata-private.h b/src/tracker-indexer/tracker-module-metadata-private.h
index c55526c..24c9e53 100644
--- a/src/tracker-indexer/tracker-module-metadata-private.h
+++ b/src/tracker-indexer/tracker-module-metadata-private.h
@@ -36,6 +36,7 @@ typedef void (* TrackerModuleMetadataForeach) (const gchar *subject,
void tracker_module_metadata_foreach (TrackerModuleMetadata *metadata,
TrackerModuleMetadataForeach func,
gpointer user_data);
+gchar * tracker_module_metadata_get_sparql (TrackerModuleMetadata *metadata);
G_END_DECLS
diff --git a/src/tracker-indexer/tracker-module-metadata.c b/src/tracker-indexer/tracker-module-metadata.c
index 541953e..bfc9d4d 100644
--- a/src/tracker-indexer/tracker-module-metadata.c
+++ b/src/tracker-indexer/tracker-module-metadata.c
@@ -307,6 +307,33 @@ tracker_module_metadata_foreach (TrackerModuleMetadata *metadata,
}
}
+gchar *
+tracker_module_metadata_get_sparql (TrackerModuleMetadata *metadata)
+{
+ GString *sparql;
+ gint i;
+
+ sparql = g_string_new ("INSERT {");
+
+ for (i = 0; i < metadata->statements->len; i++) {
+ Statement *stmt;
+ gchar *object;
+
+ stmt = &g_array_index (metadata->statements, Statement, i);
+
+ object = g_strescape (stmt->object, NULL);
+
+ g_string_append_printf (sparql, " <%s> <%s> \"%s\" .",
+ stmt->subject, stmt->predicate, object);
+
+ g_free (object);
+ }
+
+ g_string_append (sparql, " }");
+
+ return g_string_free (sparql, FALSE);
+}
+
/**
* tracker_module_metadata_new:
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]