[tracker] Add initial SQLite FTS support



commit 7fae774a0522fe0cc235fb82efac1c33b0c64d3b
Author: Jürg Billeter <j bitron ch>
Date:   Fri Apr 17 18:05:00 2009 +0200

    Add initial SQLite FTS support
---
 configure.ac                                    |   34 ++--
 data/db/Makefile.am                             |    1 -
 data/db/sqlite-fulltext.sql                     |  258 -----------------------
 src/Makefile.am                                 |    2 +
 src/libtracker-data/Makefile.am                 |   22 ++-
 src/libtracker-data/tracker-data-manager.c      |   41 ++++
 src/libtracker-data/tracker-data-update.c       |   68 ++++++-
 src/libtracker-data/tracker-sparql-query.vala   |    6 +
 src/libtracker-db/Makefile.am                   |   18 +-
 src/libtracker-db/tracker-db-interface-sqlite.c |   15 ++
 src/libtracker-db/tracker-db-manager.c          |   17 +-
 src/tracker-fts/Makefile.am                     |    3 +-
 src/tracker-fts/tracker-fts.c                   |    4 +
 src/tracker-indexer/tracker-indexer.c           |   21 ++-
 src/tracker-utils/tracker-processes.c           |    2 +
 src/trackerd/tracker-dbus.c                     |    2 +
 src/trackerd/tracker-main.c                     |    5 +-
 src/trackerd/tracker-processor.c                |    4 +
 src/trackerd/tracker-search.c                   |    8 +
 tests/libtracker-db/Makefile.am                 |    2 +
 utils/Makefile.am                               |    9 +
 utils/tracker-fts/.gitignore                    |    1 +
 22 files changed, 234 insertions(+), 309 deletions(-)

diff --git a/configure.ac b/configure.ac
index 99c4489..42e5786 100644
--- a/configure.ac
+++ b/configure.ac
@@ -341,6 +341,23 @@ fi
 
 AM_CONDITIONAL(HAVE_UNIT_TESTS, test "x$have_unit_tests" = "xyes")
 
+##################################################################
+# Enable SQLite FTS support?
+##################################################################
+
+AC_ARG_ENABLE([sqlite_fts],
+              AS_HELP_STRING([--enable-sqlite-fts], 
+	                     [enable SQLite FTS support (default=no)]),,
+              [enable_sqlite_fts=no])
+
+if test "x$enable_sqlite_fts" != "xno" ; then
+   AC_DEFINE(HAVE_SQLITE_FTS, 1, [Define if we have SQLite FTS support])
+else
+   enable_sqlite_fts="no  (disabled)"
+fi
+
+AM_CONDITIONAL(ENABLE_SQLITE_FTS, test "$enable_sqlite_fts" = "yes")
+
 ####################################################################
 # QDBM check
 ####################################################################
@@ -359,7 +376,7 @@ if test "x$enable_external_qdbm" != "xno"; then
    if test "x$have_external_qdbm" = "xyes"; then
       AC_DEFINE(HAVE_EXTERNAL_QDBM, [], [Define if we have external QDBM])
    fi
-else
+elif test "x$enable_sqlite_fts" != "xyes" ; then
    QDBM_CFLAGS="-I\$(top_srcdir)/src/qdbm"
    QDBM_LIBS="\$(top_builddir)/src/qdbm/libqdbm-private.la"
    AC_DEFINE(HAVE_QDBM, [], [Define if we have QDBM (our imported version)])
@@ -1310,21 +1327,6 @@ fi
 
 AM_CONDITIONAL(HAVE_EVOLUTION_PLUGIN, test "$have_evolution_plugin" = "yes")
 
-##################################################################
-# Enable SQLite FTS support?
-##################################################################
-
-AC_ARG_ENABLE([sqlite_fts],
-              AS_HELP_STRING([--enable-sqlite-fts], 
-	                     [enable SQLite FTS support (default=no)]),,
-              [enable_sqlite_fts=no])
-
-if test "x$enable_sqlite_fts" != "xyes" ; then
-   enable_sqlite_fts="no  (disabled)"
-fi
-
-AM_CONDITIONAL(ENABLE_SQLITE_FTS, test "$enable_sqlite_fts" = "yes")
-
 ####################################################################
 # Checks for gtk-doc and docbook-tools
 ####################################################################
diff --git a/data/db/Makefile.am b/data/db/Makefile.am
index 0275ea1..9a192cd 100644
--- a/data/db/Makefile.am
+++ b/data/db/Makefile.am
@@ -4,7 +4,6 @@ configdir = $(datadir)/tracker
 
 config_DATA =				\
 	sqlite-contents.sql		\
-	sqlite-fulltext.sql 		\
 	sqlite-tracker.sql
 
 EXTRA_DIST = $(config_DATA)
diff --git a/data/db/sqlite-fulltext.sql b/data/db/sqlite-fulltext.sql
deleted file mode 100644
index 614e617..0000000
--- a/data/db/sqlite-fulltext.sql
+++ /dev/null
@@ -1,258 +0,0 @@
-create virtual table FullText using trackerfts (
-cat, 
-col_default, 
-col_1,
-col_2,
-col_3,
-col_4,
-col_5,
-col_6,
-col_7,
-col_8,
-col_9,
-col_10,
-col_11,
-col_12,
-col_13,
-col_14,
-col_15,
-col_16,
-col_17,
-col_18,
-col_19,
-col_20,
-col_21,
-col_22,
-col_23,
-col_24,
-col_25,
-col_26,
-col_27,
-col_28,
-col_29,
-col_30,
-col_31,
-col_32,
-col_33,
-col_34,
-col_35,
-col_36,
-col_37,
-col_38,
-col_39,
-col_40,
-col_41,
-col_42,
-col_43,
-col_44,
-col_45,
-col_46,
-col_47,
-col_48,
-col_49,
-col_50,
-col_51,
-col_52,
-col_53,
-col_54,
-col_55,
-col_56,
-col_57,
-col_58,
-col_59,
-col_60,
-col_61,
-col_62,
-col_63,
-col_64,
-col_65,
-col_66,
-col_67,
-col_68,
-col_69,
-col_70,
-col_71,
-col_72,
-col_73,
-col_74,
-col_75,
-col_76,
-col_77,
-col_78,
-col_79,
-col_80,
-col_81,
-col_82,
-col_83,
-col_84,
-col_85,
-col_86,
-col_87,
-col_88,
-col_89,
-col_90,
-col_91,
-col_92,
-col_93,
-col_94,
-col_95,
-col_96,
-col_97,
-col_98,
-col_99,
-col_100,
-col_101,
-col_102,
-col_103,
-col_104,
-col_105,
-col_106,
-col_107,
-col_108,
-col_109,
-col_110,
-col_111,
-col_112,
-col_113,
-col_114,
-col_115,
-col_116,
-col_117,
-col_118,
-col_119,
-col_120,
-col_121,
-col_122,
-col_123,
-col_124,
-col_125,
-col_126,
-col_127,
-col_128,
-col_129,
-col_130,
-col_131,
-col_132,
-col_133,
-col_134,
-col_135,
-col_136,
-col_137,
-col_138,
-col_139,
-col_140,
-col_141,
-col_142,
-col_143,
-col_144,
-col_145,
-col_146,
-col_147,
-col_148,
-col_149,
-col_150,
-col_151,
-col_152,
-col_153,
-col_154,
-col_155,
-col_156,
-col_157,
-col_158,
-col_159,
-col_160,
-col_161,
-col_162,
-col_163,
-col_164,
-col_165,
-col_166,
-col_167,
-col_168,
-col_169,
-col_170,
-col_171,
-col_172,
-col_173,
-col_174,
-col_175,
-col_176,
-col_177,
-col_178,
-col_179,
-col_180,
-col_181,
-col_182,
-col_183,
-col_184,
-col_185,
-col_186,
-col_187,
-col_188,
-col_189,
-col_190,
-col_191,
-col_192,
-col_193,
-col_194,
-col_195,
-col_196,
-col_197,
-col_198,
-col_199,
-col_200,
-col_201,
-col_202,
-col_203,
-col_204,
-col_205,
-col_206,
-col_207,
-col_208,
-col_209,
-col_210,
-col_211,
-col_212,
-col_213,
-col_214,
-col_215,
-col_216,
-col_217,
-col_218,
-col_219,
-col_220,
-col_221,
-col_222,
-col_223,
-col_224,
-col_225,
-col_226,
-col_227,
-col_228,
-col_229,
-col_230,
-col_231,
-col_232,
-col_233,
-col_234,
-col_235,
-col_236,
-col_237,
-col_238,
-col_239,
-col_240,
-col_241,
-col_242,
-col_243,
-col_244,
-col_245,
-col_246,
-col_247,
-col_248,
-col_249,
-col_250,
-col_251,
-col_252,
-col_253,
-col_254,
-col_255);
diff --git a/src/Makefile.am b/src/Makefile.am
index bbb6553..9ceacb9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,8 +5,10 @@ build_libinotify = libinotify
 endif
 
 if !HAVE_EXTERNAL_QDBM
+if !ENABLE_SQLITE_FTS
 build_qdbm = qdbm
 endif
+endif
 
 if ENABLE_SQLITE_FTS
 build_sqlite_fts = tracker-fts
diff --git a/src/libtracker-data/Makefile.am b/src/libtracker-data/Makefile.am
index 4318784..982165a 100644
--- a/src/libtracker-data/Makefile.am
+++ b/src/libtracker-data/Makefile.am
@@ -25,25 +25,35 @@ libtracker_data_la_SOURCES = 						\
 	tracker-data-backup.c						\
 	tracker-data-manager.c						\
 	tracker-data-query.c						\
-	tracker-data-search.c						\
 	tracker-data-update.c						\
-	tracker-query-tree.c						\
-	libtracker-data.vala.stamp					\
 	tracker-turtle.c						\
+	libtracker-data.vala.stamp					\
 	$(libtracker_data_la_VALASOURCES:.vala=.c)
 
 noinst_HEADERS =							\
 	tracker-data-backup.h						\
 	tracker-data-manager.h						\
 	tracker-data-query.h						\
-	tracker-data-search.h						\
 	tracker-data-update.h						\
-	tracker-query-tree.h						\
 	tracker-sparql-query.h						\
 	tracker-turtle.h
 
+if ENABLE_SQLITE_FTS
+VALAFLAGS = -D HAVE_SQLITE_FTS
+endif
+
+if !ENABLE_SQLITE_FTS
+libtracker_data_la_SOURCES += 						\
+	tracker-data-search.c						\
+	tracker-query-tree.c
+
+noinst_HEADERS +=							\
+	tracker-data-search.h						\
+	tracker-query-tree.h
+endif
+
 libtracker-data.vala.stamp: $(libtracker_data_la_VALASOURCES)
-	$(VALAC) -C -H tracker-sparql-query.h ../rasqal/rasqal.vapi ../libtracker-common/libtracker-common.vapi libtracker-data.vapi ../libtracker-db/libtracker-db.vapi $^
+	$(VALAC) -C $(VALAFLAGS) -H tracker-sparql-query.h ../rasqal/rasqal.vapi ../libtracker-common/libtracker-common.vapi libtracker-data.vapi ../libtracker-db/libtracker-db.vapi $^
 	touch $@
 
 libtracker_data_la_LDFLAGS =						\
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 008fd2d..01daf6a 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -745,6 +745,37 @@ create_decomposed_transient_metadata_tables (TrackerDBInterface *iface)
 	g_free (properties);
 }
 
+#ifdef HAVE_SQLITE_FTS
+static void
+create_fts_table (TrackerDBInterface *iface)
+{
+	GString    *sql;
+	TrackerProperty	  **properties, **property;
+	gboolean first;
+
+	sql = g_string_new ("CREATE VIRTUAL TABLE fulltext.fts USING trackerfts (");
+
+	first = TRUE;
+	properties = tracker_ontology_get_properties ();
+	for (property = properties; *property; property++) {
+		if (tracker_property_get_data_type (*property) == TRACKER_PROPERTY_TYPE_STRING) {
+			if (first) {
+				first = FALSE;
+			} else {
+				g_string_append (sql, ", ");
+			}
+			g_string_append_printf (sql, "\"%s\"", tracker_property_get_name (*property));
+		}
+	}
+	g_free (properties);
+
+	g_string_append (sql, ")");
+	tracker_db_interface_execute_query (iface, NULL, "%s", sql->str);
+
+	g_string_free (sql, TRUE);
+}
+#endif
+
 gboolean
 tracker_data_manager_init (TrackerConfig              *config,
 			   TrackerLanguage            *language,
@@ -776,12 +807,16 @@ tracker_data_manager_init (TrackerConfig              *config,
 			      private,
 			      private_free);
 
+#ifdef HAVE_SQLITE_FTS
+	tracker_db_manager_init (flags, &is_first_time_index, FALSE);
+#else
 	tracker_db_manager_init (flags, &is_first_time_index, TRUE);
 	if (!tracker_db_index_manager_init (index_flags,
 					    tracker_config_get_min_bucket_count (config),
 					    tracker_config_get_max_bucket_count (config))) {
 		return FALSE;
 	}
+#endif
 
 	if (first_time != NULL) {
 		*first_time = is_first_time_index;
@@ -855,6 +890,10 @@ tracker_data_manager_init (TrackerConfig              *config,
 			create_decomposed_metadata_tables (iface, *cl, &max_id);
 		}
 
+#ifdef HAVE_SQLITE_FTS
+		create_fts_table (iface);
+#endif
+
 		/* store ontology in database */
 		for (l = sorted; l; l = l->next) {
 			import_ontology_file (l->data);
@@ -887,7 +926,9 @@ tracker_data_manager_shutdown (void)
 {
 	TrackerDBPrivate *private;
 
+#ifndef HAVE_SQLITE_FTS
 	tracker_db_index_manager_shutdown ();
+#endif
 	tracker_db_manager_shutdown ();
 
 	private = g_static_private_get (&private_key);
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index ec6b33f..0ed2808 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -58,6 +58,7 @@ struct _TrackerDataUpdateBuffer {
 struct _TrackerDataUpdateBufferProperty {
 	gchar *name;
 	GValue value;
+	gboolean fts;
 };
 
 struct _TrackerDataUpdateBufferTable {
@@ -205,13 +206,15 @@ static void
 cache_insert_value (const gchar            *table_name,
 		    const gchar            *field_name,
 		    GValue                 *value,
-		    gboolean                multiple_values)
+		    gboolean                multiple_values,
+		    gboolean                fts)
 {
 	TrackerDataUpdateBufferTable    *table;
 	TrackerDataUpdateBufferProperty  property;
 
 	property.name = g_strdup (field_name);
 	property.value = *value;
+	property.fts = fts;
 
 	table = cache_ensure_table (table_name, multiple_values);
 	g_array_append_val (table->properties, property);
@@ -275,6 +278,13 @@ ensure_resource_id (const gchar *uri)
 		tracker_db_statement_execute (stmt, NULL);
 		g_object_unref (stmt);
 
+#ifdef HAVE_SQLITE_FTS
+		stmt = tracker_db_interface_create_statement (iface, "INSERT INTO \"fts\" (rowid) VALUES (?)");
+		tracker_db_statement_bind_int (stmt, 0, id);
+		tracker_db_statement_execute (stmt, NULL);
+		g_object_unref (stmt);
+#endif
+
 		g_hash_table_insert (update_buffer.resource_cache, g_strdup (uri), GUINT_TO_POINTER (id));
 	}
 
@@ -314,11 +324,16 @@ tracker_data_update_buffer_flush (void)
 	TrackerDataUpdateBufferProperty *property;
 	GHashTableIter                  iter;
 	const gchar                    *table_name;
-	GString                        *sql;
-	int                             i;
+	GString                        *sql, *fts_sql;
+	int                             i, fts_index;
 
 	iface = tracker_db_manager_get_db_interface ();
 
+#ifdef HAVE_SQLITE_FTS
+	fts_sql = g_string_new ("UPDATE \"fts\" SET ");
+	fts_index = 0;
+#endif
+
 	g_hash_table_iter_init (&iter, update_buffer.tables);
 	while (g_hash_table_iter_next (&iter, (gpointer*) &table_name, (gpointer*) &table)) {
 		if (table->multiple_values) {
@@ -375,8 +390,43 @@ tracker_data_update_buffer_flush (void)
 
 			g_string_free (sql, TRUE);
 		}
+
+#ifdef HAVE_SQLITE_FTS
+		for (i = 0; i < table->properties->len; i++) {
+			property = &g_array_index (table->properties, TrackerDataUpdateBufferProperty, i);
+			if (property->fts) {
+				if (fts_index > 0) {
+					g_string_append (fts_sql, ", ");
+				}
+				g_string_append_printf (fts_sql, "\"%s\" = ?", property->name);
+				fts_index++;
+			}
+		}
+#endif
 	}
 
+#ifdef HAVE_SQLITE_FTS
+	if (fts_index > 0) {
+		g_string_append (fts_sql, " WHERE rowid = ?");
+
+		stmt = tracker_db_interface_create_statement (iface, "%s", fts_sql->str);
+		tracker_db_statement_bind_int (stmt, fts_index, update_buffer.id);
+
+		fts_index = 0;
+		for (i = 0; i < table->properties->len; i++) {
+			property = &g_array_index (table->properties, TrackerDataUpdateBufferProperty, i);
+			if (property->fts) {
+				statement_bind_gvalue (stmt, fts_index, &property->value);
+				fts_index++;
+			}
+		}
+
+		tracker_db_statement_execute (stmt, NULL);
+		g_object_unref (stmt);
+	}
+	g_string_free (fts_sql, TRUE);
+#endif
+
 	g_hash_table_remove_all (update_buffer.tables);
 	g_free (update_buffer.subject);
 	update_buffer.subject = NULL;
@@ -465,7 +515,7 @@ cache_create_service_decomposed (TrackerClass           *cl)
 	cache_insert_row (tracker_class_get_name (cl));
 
 	g_value_set_int (&gvalue, ensure_resource_id (tracker_class_get_uri (cl)));
-	cache_insert_value ("rdfs:Resource_rdf:type", "rdf:type", &gvalue, TRUE);
+	cache_insert_value ("rdfs:Resource_rdf:type", "rdf:type", &gvalue, TRUE, FALSE);
 }
 
 guint32
@@ -523,7 +573,7 @@ cache_set_metadata_decomposed (TrackerProperty	*property,
 			       const gchar	*value)
 {
 	guint32		    object_id;
-	gboolean            multiple_values;
+	gboolean            multiple_values, fts;
 	gchar              *table_name;
 	const gchar        *field_name;
 	TrackerProperty   **super_properties;
@@ -577,7 +627,9 @@ cache_set_metadata_decomposed (TrackerProperty	*property,
 		return;
 	}
 
-	cache_insert_value (table_name, field_name, &gvalue, multiple_values);
+	fts = tracker_property_get_fulltext_indexed (property);
+
+	cache_insert_value (table_name, field_name, &gvalue, multiple_values, fts);
 
 	g_free (table_name);
 }
@@ -591,6 +643,7 @@ send_text_to_index (TrackerConfig  *config,
 		    gboolean	    full_parsing,
 		    gint	    weight_factor)
 {
+#ifndef HAVE_SQLITE_FTS
 	TrackerDBIndex *lindex;
 	GHashTable     *parsed;
 	GHashTableIter	iter;
@@ -631,6 +684,7 @@ send_text_to_index (TrackerConfig  *config,
 	}
 
 	g_hash_table_unref (parsed);
+#endif
 }
 
 static void
@@ -1050,7 +1104,7 @@ tracker_data_insert_statement (const gchar            *subject,
 		update_buffer.types = tracker_data_query_rdf_type (update_buffer.id);
 
 		g_value_set_int64 (&gvalue, (gint64) time (NULL));
-		cache_insert_value ("rdfs:Resource", "Modified", &gvalue, FALSE);
+		cache_insert_value ("rdfs:Resource", "Modified", &gvalue, FALSE, FALSE);
 	}
 
 	if (strcmp (predicate, RDF_PREFIX "type") == 0) {
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index eccfa95..c714eda 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -681,6 +681,11 @@ public class Tracker.SparqlQuery : Object {
 				pattern_sql.append (binding.sql_db_column_name);
 				pattern_sql.append ("\"");
 				if (binding.is_fts_match) {
+#if HAVE_SQLITE_FTS
+					// parameters do not work with fts MATCH
+					string escaped_literal = string.joinv ("''", binding.literal.split ("'"));
+					pattern_sql.append_printf (" IN (SELECT rowid FROM fts WHERE fts MATCH '%s')", escaped_literal);
+#else
 					pattern_sql.append (" IN (");
 
 					// include matches from fulltext search
@@ -695,6 +700,7 @@ public class Tracker.SparqlQuery : Object {
 					}
 
 					pattern_sql.append (")");
+#endif
 				} else {
 					pattern_sql.append (" = ");
 					if (binding.is_uri) {
diff --git a/src/libtracker-db/Makefile.am b/src/libtracker-db/Makefile.am
index 4cfb835..14a32d4 100644
--- a/src/libtracker-db/Makefile.am
+++ b/src/libtracker-db/Makefile.am
@@ -19,9 +19,6 @@ libtracker_db_la_SOURCES = 						\
 	tracker-db-action.c						\
 	tracker-db-dbus.c						\
 	tracker-db-file-info.c						\
-	tracker-db-index.c						\
-	tracker-db-index-item.c						\
-	tracker-db-index-manager.c					\
 	tracker-db-interface.c						\
 	tracker-db-interface-sqlite.c					\
 	tracker-db-manager.c
@@ -30,13 +27,22 @@ noinst_HEADERS =							\
 	tracker-db-action.h						\
 	tracker-db-dbus.h						\
 	tracker-db-file-info.h						\
-	tracker-db-index.h						\
-	tracker-db-index-item.h						\
-	tracker-db-index-manager.h					\
 	tracker-db-interface.h						\
 	tracker-db-interface-sqlite.h					\
 	tracker-db-manager.h 
 
+if !ENABLE_SQLITE_FTS
+libtracker_db_la_SOURCES += 						\
+	tracker-db-index.c						\
+	tracker-db-index-item.c						\
+	tracker-db-index-manager.c
+
+noinst_HEADERS +=							\
+	tracker-db-index.h						\
+	tracker-db-index-item.h						\
+	tracker-db-index-manager.h
+endif
+
 libtracker_db_la_LDFLAGS =						\
 	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
 
diff --git a/src/libtracker-db/tracker-db-interface-sqlite.c b/src/libtracker-db/tracker-db-interface-sqlite.c
index 2347acc..33a7d84 100644
--- a/src/libtracker-db/tracker-db-interface-sqlite.c
+++ b/src/libtracker-db/tracker-db-interface-sqlite.c
@@ -18,6 +18,8 @@
  * Boston, MA  02110-1301, USA.
  */
 
+#include "config.h"
+
 #include <glib/gstdio.h>
 #include <sqlite3.h>
 
@@ -99,6 +101,7 @@ tracker_db_interface_sqlite_constructor (GType			type,
 {
 	GObject *object;
 	TrackerDBInterfaceSqlitePrivate *priv;
+	gchar *err_msg = NULL;
 
 	object = (* G_OBJECT_CLASS (tracker_db_interface_sqlite_parent_class)->constructor) (type,
 											     n_construct_properties,
@@ -123,6 +126,18 @@ tracker_db_interface_sqlite_constructor (GType			type,
 	sqlite3_extended_result_codes (priv->db, 0);
 	sqlite3_busy_timeout (priv->db, 10000000);
 
+#ifdef HAVE_SQLITE_FTS
+	sqlite3_enable_load_extension (priv->db, 1);
+	sqlite3_load_extension (priv->db, "tracker-fts.so", NULL, &err_msg);
+
+	if (err_msg) {
+		g_critical ("Could not load tracker-fts extension:'%s'", err_msg);
+		sqlite3_free (err_msg);
+	} else {
+		g_message ("Loaded tracker fts extension");
+	}
+#endif
+
 	return object;
 }
 
diff --git a/src/libtracker-db/tracker-db-manager.c b/src/libtracker-db/tracker-db-manager.c
index a4bd271..5dc29c1 100644
--- a/src/libtracker-db/tracker-db-manager.c
+++ b/src/libtracker-db/tracker-db-manager.c
@@ -796,15 +796,6 @@ db_interface_get_fulltext (void)
 
 	iface = db_interface_get (TRACKER_DB_FULLTEXT, &create);
 
-	/*
-	 * disabled to avoid warnings while not implemented
-	if (create) {
-		tracker_db_interface_start_transaction (iface);
-		load_sql_file (iface, "sqlite-fulltext.sql", NULL);
-		tracker_db_interface_end_transaction (iface);
-	}
-	 */
-
 	return iface;
 }
 
@@ -1214,10 +1205,18 @@ tracker_db_manager_init (TrackerDBManagerFlags	flags,
 
 	initialized = TRUE;
 
+#ifdef HAVE_SQLITE_FTS
+	resources_iface = tracker_db_manager_get_db_interfaces (4,
+							    TRACKER_DB_METADATA,
+							    TRACKER_DB_FULLTEXT,
+							    TRACKER_DB_CONTENTS,
+							    TRACKER_DB_COMMON);
+#else
 	resources_iface = tracker_db_manager_get_db_interfaces (3,
 							    TRACKER_DB_METADATA,
 							    TRACKER_DB_CONTENTS,
 							    TRACKER_DB_COMMON);
+#endif
 }
 
 void
diff --git a/src/tracker-fts/Makefile.am b/src/tracker-fts/Makefile.am
index 270726e..2fa9948 100644
--- a/src/tracker-fts/Makefile.am
+++ b/src/tracker-fts/Makefile.am
@@ -6,8 +6,7 @@ INCLUDES =							\
 	$(GLIB2_CFLAGS)						\
 	$(GCOV_CFLAGS)						\
 	$(PANGO_CFLAGS)						\
-	$(SQLITE3_CFLAGS)					\
-	-DSTORE_CATEGORY=1			
+	$(SQLITE3_CFLAGS)
 
 module_flags = -module -avoid-version -no-undefined
 
diff --git a/src/tracker-fts/tracker-fts.c b/src/tracker-fts/tracker-fts.c
index 5fa6414..76276aa 100644
--- a/src/tracker-fts/tracker-fts.c
+++ b/src/tracker-fts/tracker-fts.c
@@ -312,6 +312,7 @@ SQLITE_EXTENSION_INIT1
 static int default_column = 0;
 
 /* Functions from Tracker */
+#if 0
 static TrackerDBResultSet *
 db_metadata_get (TrackerDBInterface *iface, 
 		 const gchar        *id, 
@@ -386,6 +387,7 @@ db_get_text (const char     *service,
 
 	return contents;
 }
+#endif
 
 static inline int
 get_metadata_weight (int id)
@@ -4221,7 +4223,9 @@ static int fulltextNext(sqlite3_vtab_cursor *pCursor){
     }
     rc = sqlite3_bind_int64(c->pStmt, 1, dlrDocid(&c->reader));
     c->currentDocid = dlrDocid(&c->reader);
+#ifdef STORE_CATEGORY
     c->currentCatid = dlrCatid(&c->reader);
+#endif
 
     /* (tracker) read position offsets here */
     
diff --git a/src/tracker-indexer/tracker-indexer.c b/src/tracker-indexer/tracker-indexer.c
index 5c1ea82..0645ef9 100644
--- a/src/tracker-indexer/tracker-indexer.c
+++ b/src/tracker-indexer/tracker-indexer.c
@@ -403,7 +403,9 @@ flush_data (TrackerIndexer *indexer)
 		stop_transaction (indexer);
 	}
 
+#ifndef HAVE_SQLITE_FTS
 	tracker_db_index_flush (indexer->private->resources_index);
+#endif
 
 	if ((indexer->private->state & TRACKER_INDEXER_STATE_STOPPED) == 0) {
 		signal_status (indexer, "flush");
@@ -528,6 +530,7 @@ notify_battery_in_use_cb (GObject *gobject,
 
 #endif /* HAVE_HAL */
 
+#ifndef HAVE_SQLITE_FTS
 static void
 index_flushing_notify_cb (GObject        *object,
 			  GParamSpec     *pspec,
@@ -566,6 +569,7 @@ index_error_received_cb (TrackerDBIndex *index,
 	g_signal_emit (indexer, signals[INDEXING_ERROR], 0,
 		       error->message, TRUE);
 }
+#endif
 
 static void
 check_mount_removal (GQueue   *queue,
@@ -667,6 +671,7 @@ tracker_indexer_finalize (GObject *object)
 	g_object_unref (priv->language);
 	g_object_unref (priv->config);
 
+#ifndef HAVE_SQLITE_FTS
 	g_signal_handlers_disconnect_by_func (priv->resources_index,
 					      index_flushing_notify_cb,
 					      object);
@@ -674,6 +679,7 @@ tracker_indexer_finalize (GObject *object)
 					      index_overloaded_notify_cb,
 					      object);
 	g_object_unref (priv->resources_index);
+#endif
 
 	g_free (priv->db_dir);
 
@@ -865,8 +871,10 @@ check_started (TrackerIndexer *indexer)
 
 	indexer->private->timer = g_timer_new ();
 
+#ifndef HAVE_SQLITE_FTS
 	/* Open indexes */
 	tracker_db_index_open (indexer->private->resources_index);
+#endif
 
 	g_signal_emit (indexer, signals[STARTED], 0);
 }
@@ -889,8 +897,10 @@ check_finished (TrackerIndexer *indexer,
 		indexer->private->timer = NULL;
 	}
 
+#ifndef HAVE_SQLITE_FTS
 	/* Close indexes */
 	tracker_db_index_close (indexer->private->resources_index);
+#endif
 
 	/* Print out how long it took us */
 	str = tracker_seconds_to_string (seconds_elapsed, FALSE);
@@ -927,7 +937,10 @@ check_stopped (TrackerIndexer *indexer,
 		/* If the indexer is stopped and the indices aren't
 		 * being flushed, then it's ready for finishing right away
 		 */
-		if (!tracker_db_index_get_flushing (indexer->private->resources_index)) {
+#ifndef HAVE_SQLITE_FTS
+		if (!tracker_db_index_get_flushing (indexer->private->resources_index))
+#endif
+		{
 			check_finished (indexer, interrupted);
 		}
 	}
@@ -1053,6 +1066,7 @@ tracker_indexer_init (TrackerIndexer *indexer)
 
 	tracker_indexer_load_modules (indexer);
 
+#ifndef HAVE_SQLITE_FTS
 	/* Set up indexer */
 	lindex = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_RESOURCES);
 	priv->resources_index = g_object_ref (lindex);
@@ -1063,6 +1077,7 @@ tracker_indexer_init (TrackerIndexer *indexer)
 			  G_CALLBACK (index_overloaded_notify_cb), indexer);
 	g_signal_connect (priv->resources_index, "error-received",
 			  G_CALLBACK (index_error_received_cb), indexer);
+#endif
 
 	/* Set up volume monitor */
 	priv->volume_monitor = g_volume_monitor_get ();
@@ -2164,11 +2179,15 @@ tracker_indexer_set_running (TrackerIndexer *indexer,
 	if (running && (state & TRACKER_INDEXER_STATE_PAUSED)) {
 		state_unset_flags (indexer, TRACKER_INDEXER_STATE_PAUSED);
 
+#ifndef HAVE_SQLITE_FTS
 		tracker_db_index_set_paused (indexer->private->resources_index, FALSE);
+#endif
 	} else if (!running && !(state & TRACKER_INDEXER_STATE_PAUSED)) {
 		state_set_flags (indexer, TRACKER_INDEXER_STATE_PAUSED);
 
+#ifndef HAVE_SQLITE_FTS
 		tracker_db_index_set_paused (indexer->private->resources_index, TRUE);
+#endif
 	}
 }
 
diff --git a/src/tracker-utils/tracker-processes.c b/src/tracker-utils/tracker-processes.c
index 1ac3017..9b4b696 100644
--- a/src/tracker-utils/tracker-processes.c
+++ b/src/tracker-utils/tracker-processes.c
@@ -253,9 +253,11 @@ main (int argc, char **argv)
 		tracker_db_manager_remove_all ();
 		tracker_db_manager_shutdown ();
 
+#ifndef HAVE_SQLITE_FTS
 		tracker_db_index_manager_init (TRACKER_DB_INDEX_MANAGER_REMOVE_ALL, 0, 0);
 		tracker_db_index_manager_remove_all ();
 		tracker_db_index_manager_shutdown ();
+#endif
 
 		/* Unset log handler */
 		g_log_remove_handler (NULL, log_handler_id);
diff --git a/src/trackerd/tracker-dbus.c b/src/trackerd/tracker-dbus.c
index 8d536d0..b746d78 100644
--- a/src/trackerd/tracker-dbus.c
+++ b/src/trackerd/tracker-dbus.c
@@ -270,7 +270,9 @@ tracker_dbus_register_objects (TrackerConfig	*config,
 
 	g_return_val_if_fail (TRACKER_IS_CONFIG (config), FALSE);
 	g_return_val_if_fail (TRACKER_IS_LANGUAGE (language), FALSE);
+#ifndef HAVE_SQLITE_FTS
 	g_return_val_if_fail (TRACKER_IS_DB_INDEX (resources_index), FALSE);
+#endif
 
 	if (!connection || !gproxy) {
 		g_critical ("DBus support must be initialized before registering objects!");
diff --git a/src/trackerd/tracker-main.c b/src/trackerd/tracker-main.c
index b036481..17de536 100644
--- a/src/trackerd/tracker-main.c
+++ b/src/trackerd/tracker-main.c
@@ -660,7 +660,6 @@ get_ttl_backup_filename (void)
 static void
 backup_user_metadata (TrackerConfig *config, TrackerLanguage *language)
 {
-	TrackerDBIndex		   *index;
 	gboolean                    is_first_time_index;
 
 	g_message ("Saving metadata in %s", get_ttl_backup_filename ());
@@ -679,8 +678,6 @@ backup_user_metadata (TrackerConfig *config, TrackerLanguage *language)
 		return;
 	}
 
-	index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_RESOURCES);
-	
 	/* Actual save of the metadata */
 	tracker_data_backup_save (get_ttl_backup_filename (), NULL);
 	
@@ -1012,12 +1009,14 @@ main (gint argc, gchar *argv[])
 		return EXIT_FAILURE;
 	}
 
+#ifndef HAVE_SQLITE_FTS
 	resources_index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_RESOURCES);
 
 	if (!TRACKER_IS_DB_INDEX (resources_index)) {
 		g_critical ("Could not create indexer for resource index");
 		return EXIT_FAILURE;
 	}
+#endif
 
 	tracker_volume_cleanup_init ();
 
diff --git a/src/trackerd/tracker-processor.c b/src/trackerd/tracker-processor.c
index a07321c..00622f3 100644
--- a/src/trackerd/tracker-processor.c
+++ b/src/trackerd/tracker-processor.c
@@ -1119,12 +1119,14 @@ indexer_status_cb (DBusGProxy  *proxy,
 			       seconds_elapsed);
 	g_free (path);
 
+#ifndef HAVE_SQLITE_FTS
 	/* Tell the index that it can reload, really we should do
 	 * module_name->index type so we don't do this for both
 	 * every time:
 	 */
 	index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_RESOURCES);
 	tracker_db_index_set_reload (index, TRUE);
+#endif
 
 	/* Message to the console about state */
 	str1 = tracker_seconds_estimate_to_string (seconds_elapsed,
@@ -1175,12 +1177,14 @@ indexer_finished_cb (DBusGProxy  *proxy,
 			       items_processed,
 			       seconds_elapsed);
 
+#ifndef HAVE_SQLITE_FTS
 	/* Tell the index that it can reload, really we should do
 	 * module_name->index type so we don't do this for both
 	 * every time:
 	 */
 	index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_RESOURCES);
 	tracker_db_index_set_reload (index, TRUE);
+#endif
 
 	/* Message to the console about state */
 	str = tracker_seconds_to_string (seconds_elapsed, FALSE);
diff --git a/src/trackerd/tracker-search.c b/src/trackerd/tracker-search.c
index 448a82d..eaebdb0 100644
--- a/src/trackerd/tracker-search.c
+++ b/src/trackerd/tracker-search.c
@@ -84,7 +84,9 @@ tracker_search_finalize (GObject *object)
 
 	priv = TRACKER_SEARCH_GET_PRIVATE (object);
 
+#ifndef HAVE_SQLITE_FTS
 	g_object_unref (priv->resources_index);
+#endif
 	g_object_unref (priv->language);
 	g_object_unref (priv->config);
 
@@ -101,7 +103,9 @@ tracker_search_new (TrackerConfig   *config,
 
 	g_return_val_if_fail (TRACKER_IS_CONFIG (config), NULL);
 	g_return_val_if_fail (TRACKER_IS_LANGUAGE (language), NULL);
+#ifndef HAVE_SQLITE_FTS
 	g_return_val_if_fail (TRACKER_IS_DB_INDEX (resources_index), NULL);
+#endif
 
 	object = g_object_new (TRACKER_TYPE_SEARCH, NULL);
 
@@ -109,7 +113,9 @@ tracker_search_new (TrackerConfig   *config,
 
 	priv->config = g_object_ref (config);
 	priv->language = g_object_ref (language);
+#ifndef HAVE_SQLITE_FTS
 	priv->resources_index = g_object_ref (resources_index);
+#endif
 
 	return object;
 }
@@ -508,6 +514,7 @@ tracker_search_suggest (TrackerSearch	       *object,
 
 	priv = TRACKER_SEARCH_GET_PRIVATE (object);
 
+#ifndef HAVE_SQLITE_FTS
 	value = tracker_db_index_get_suggestion (priv->resources_index,
 						 search_text,
 						 max_dist);
@@ -528,6 +535,7 @@ tracker_search_suggest (TrackerSearch	       *object,
 				      search_text, value);
 		g_free (value);
 	}
+#endif
 
 	tracker_dbus_request_success (request_id);
 }
diff --git a/tests/libtracker-db/Makefile.am b/tests/libtracker-db/Makefile.am
index 090c1ae..558af6e 100644
--- a/tests/libtracker-db/Makefile.am
+++ b/tests/libtracker-db/Makefile.am
@@ -16,8 +16,10 @@ noinst_PROGRAMS = $(TEST_PROGS)
 #	  tracker-db-manager-custom
 #
 
+if !ENABLE_SQLITE_FTS
 TEST_PROGS += 								\
 	tracker-index-writer
+endif
 
 INCLUDES = 								\
 	-DG_LOG_DOMAIN=\"Tracker\"					\
diff --git a/utils/Makefile.am b/utils/Makefile.am
index bfe190c..5fd1e21 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -4,7 +4,16 @@ if ENABLE_SQLITE_FTS
 build_sqlite_fts = tracker-fts
 endif
 
+if !ENABLE_SQLITE_FTS
+build_qdbm = qdbm
+endif
+
 SUBDIRS = 			\
 	services		\
 	$(build_sqlite_fts)	\
+	$(build_qdbm)
+
+DIST_SUBDIRS = 			\
+	services		\
+	tracker-fts		\
 	qdbm
diff --git a/utils/tracker-fts/.gitignore b/utils/tracker-fts/.gitignore
new file mode 100644
index 0000000..ecd52e1
--- /dev/null
+++ b/utils/tracker-fts/.gitignore
@@ -0,0 +1 @@
+tracker-fts-test



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