tracker r2137 - in branches/indexer-split: . data/services src/libtracker-common src/libtracker-db src/tracker-indexer src/trackerd tests/libtracker-common



Author: mr
Date: Thu Aug 21 17:33:36 2008
New Revision: 2137
URL: http://svn.gnome.org/viewvc/tracker?rev=2137&view=rev

Log:
	* data/services/default.service: Added inode/; to the prefixes to
	recognise folders like $HOME/.xchat.

	* src/libtracker-common/tracker-ontology.[ch]: 
	* tests/libtracker-common/tracker-ontology-test.c: Renamed
	tracker_ontology_get_parent_id_for_service_id() to
	tracker_ontology_get_db_by_service_type() and added a check for
	NULL service strings.

	* src/libtracker-common/tracker-parser.c: Cleaned up the code,
	fixed a nasty double free that was introduced recently. Do proper
	type checking for TrackerLanguage. Make sure we reference the
	language and unreference it when creating/freeing the parser.

	* src/libtracker-db/tracker-db-index-manager.[ch]:
	* src/tracker-indexer/tracker-indexer.c: 
	* src/trackerd/tracker-db.c: 
	* src/trackerd/tracker-dbus.[ch]: 
	* src/trackerd/tracker-main.c: 
	* src/trackerd/tracker-processor.c: Now we have all email words
	indexed to their own email-index.db file instead of filling up one
	big index.db file. This was causing serious performance issues.


Modified:
   branches/indexer-split/ChangeLog
   branches/indexer-split/data/services/default.service
   branches/indexer-split/src/libtracker-common/tracker-ontology.c
   branches/indexer-split/src/libtracker-common/tracker-ontology.h
   branches/indexer-split/src/libtracker-common/tracker-parser.c
   branches/indexer-split/src/libtracker-common/tracker-service.c
   branches/indexer-split/src/libtracker-common/tracker-service.h
   branches/indexer-split/src/libtracker-db/tracker-db-index-manager.c
   branches/indexer-split/src/libtracker-db/tracker-db-index-manager.h
   branches/indexer-split/src/libtracker-db/tracker-db-manager.c
   branches/indexer-split/src/libtracker-db/tracker-db-manager.h
   branches/indexer-split/src/tracker-indexer/tracker-indexer.c
   branches/indexer-split/src/trackerd/tracker-db.c
   branches/indexer-split/src/trackerd/tracker-db.h
   branches/indexer-split/src/trackerd/tracker-dbus.c
   branches/indexer-split/src/trackerd/tracker-dbus.h
   branches/indexer-split/src/trackerd/tracker-main.c
   branches/indexer-split/src/trackerd/tracker-processor.c
   branches/indexer-split/src/trackerd/tracker-query-tree.c
   branches/indexer-split/src/trackerd/tracker-query-tree.h
   branches/indexer-split/src/trackerd/tracker-search.c
   branches/indexer-split/src/trackerd/tracker-search.h
   branches/indexer-split/tests/libtracker-common/tracker-ontology-test.c

Modified: branches/indexer-split/data/services/default.service
==============================================================================
--- branches/indexer-split/data/services/default.service	(original)
+++ branches/indexer-split/data/services/default.service	Thu Aug 21 17:33:36 2008
@@ -13,7 +13,7 @@
 Parent=Files
 UIVisible=true
 UIView=icon
-MimePrefixes=x-directory/
+MimePrefixes=x-directory/;inode/;
 Icon=folder
 ShowServiceFiles=true
 ShowServiceDirectories=true

Modified: branches/indexer-split/src/libtracker-common/tracker-ontology.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-ontology.c	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-ontology.c	Thu Aug 21 17:33:36 2008
@@ -337,13 +337,14 @@
 }
 
 TrackerDBType
-tracker_ontology_get_db_for_service_type (const gchar *service_str)
+tracker_ontology_get_db_by_service_type (const gchar *service)
 {
 	TrackerDBType  type;
 	gchar         *str;
 
-	type = TRACKER_DB_TYPE_FILES;
-	str = g_utf8_strdown (service_str, -1);
+	g_return_val_if_fail (service != NULL, TRACKER_DB_TYPE_FILES);
+
+	str = g_utf8_strdown (service, -1);
 
 	if (g_str_has_suffix (str, "emails") || 
 	    g_str_has_suffix (str, "attachments")) {
@@ -352,6 +353,8 @@
 		type = TRACKER_DB_TYPE_FILES;
 	} else if (g_str_has_prefix (str, "xesam")) {
 		type = TRACKER_DB_TYPE_XESAM;
+	} else {
+		type = TRACKER_DB_TYPE_FILES;
 	}
 
 	g_free (str);

Modified: branches/indexer-split/src/libtracker-common/tracker-ontology.h
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-ontology.h	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-ontology.h	Thu Aug 21 17:33:36 2008
@@ -29,48 +29,48 @@
 
 G_BEGIN_DECLS
 
-void            tracker_ontology_init                         (void);
-void            tracker_ontology_shutdown                     (void);
-void            tracker_ontology_add_service_type             (TrackerService *service,
-							       GSList         *mimes,
-							       GSList         *mime_prefixes);
-TrackerService *tracker_ontology_get_service_type_by_name     (const gchar    *service_str);
-gchar *         tracker_ontology_get_service_type_by_id       (gint            id);
-gchar *         tracker_ontology_get_service_type_for_mime    (const gchar    *mime);
-gint            tracker_ontology_get_id_for_service_type      (const gchar    *service_str);
-gchar *         tracker_ontology_get_parent_service           (const gchar    *service_str);
-gchar *         tracker_ontology_get_parent_service_by_id     (gint            id);
-gint            tracker_ontology_get_parent_id_for_service_id (gint            id);
-TrackerDBType   tracker_ontology_get_db_for_service_type      (const gchar    *service_str);
-gboolean        tracker_ontology_service_type_has_embedded    (const gchar    *service_str);
-gboolean        tracker_ontology_is_valid_service_type        (const gchar    *service_str);
-gboolean        tracker_ontology_service_type_has_metadata    (const gchar    *service_str);
-gboolean        tracker_ontology_service_type_has_thumbnails  (const gchar    *service_str);
-gboolean        tracker_ontology_service_type_has_text        (const gchar    *service_str);
-gint            tracker_ontology_metadata_key_in_service      (const gchar    *service_str,
-							       const gchar    *meta_name);
-gboolean        tracker_ontology_show_service_directories     (const gchar    *service_str);
-gboolean        tracker_ontology_show_service_files           (const gchar    *service_str);
-GSList *        tracker_ontology_registered_service_types     (void);
-GSList *        tracker_ontology_registered_field_types       (const gchar    *service_type);
+void               tracker_ontology_init                         (void);
+void               tracker_ontology_shutdown                     (void);
+void               tracker_ontology_add_service_type             (TrackerService *service,
+								  GSList         *mimes,
+								  GSList         *mime_prefixes);
+TrackerService *   tracker_ontology_get_service_type_by_name     (const gchar    *service_str);
+gchar *            tracker_ontology_get_service_type_by_id       (gint            id);
+gchar *            tracker_ontology_get_service_type_for_mime    (const gchar    *mime);
+gint               tracker_ontology_get_id_for_service_type      (const gchar    *service_str);
+gchar *            tracker_ontology_get_parent_service           (const gchar    *service_str);
+gchar *            tracker_ontology_get_parent_service_by_id     (gint            id);
+gint               tracker_ontology_get_parent_id_for_service_id (gint            id);
+TrackerDBType      tracker_ontology_get_db_by_service_type       (const gchar    *service);
+gboolean           tracker_ontology_service_type_has_embedded    (const gchar    *service_str);
+gboolean           tracker_ontology_is_valid_service_type        (const gchar    *service_str);
+gboolean           tracker_ontology_service_type_has_metadata    (const gchar    *service_str);
+gboolean           tracker_ontology_service_type_has_thumbnails  (const gchar    *service_str);
+gboolean           tracker_ontology_service_type_has_text        (const gchar    *service_str);
+gint               tracker_ontology_metadata_key_in_service      (const gchar    *service_str,
+								  const gchar    *meta_name);
+gboolean           tracker_ontology_show_service_directories     (const gchar    *service_str);
+gboolean           tracker_ontology_show_service_files           (const gchar    *service_str);
+GSList *           tracker_ontology_registered_service_types     (void);
+GSList *           tracker_ontology_registered_field_types       (const gchar    *service_type);
 
 /* Service directories */
-GSList *        tracker_ontology_get_dirs_for_service_type    (const gchar    *service);
-void            tracker_ontology_add_dir_to_service_type      (const gchar    *service,
-							       const gchar    *path);
-void            tracker_ontology_remove_dir_to_service_type   (const gchar    *service,
-							       const gchar    *path);
-gchar *         tracker_ontology_get_service_type_for_dir     (const gchar    *path);
+GSList *           tracker_ontology_get_dirs_for_service_type    (const gchar    *service);
+void               tracker_ontology_add_dir_to_service_type      (const gchar    *service,
+								  const gchar    *path);
+void               tracker_ontology_remove_dir_to_service_type   (const gchar    *service,
+								  const gchar    *path);
+gchar *            tracker_ontology_get_service_type_for_dir     (const gchar    *path);
 
 /* Field handling */
-void            tracker_ontology_add_field                    (TrackerField   *field);
-gchar *         tracker_ontology_get_field_column_in_services (TrackerField   *field,
-							       const gchar    *service_type);
-gchar *         tracker_ontology_get_display_field            (TrackerField   *field);
-gboolean        tracker_ontology_field_is_child_of            (const gchar    *child,
-							       const gchar    *parent);
-TrackerField *  tracker_ontology_get_field_def                (const gchar    *name);
-const gchar *   tracker_ontology_get_field_id                 (const gchar    *name);
+void               tracker_ontology_add_field                    (TrackerField   *field);
+gchar *            tracker_ontology_get_field_column_in_services (TrackerField   *field,
+								  const gchar    *service_type);
+gchar *            tracker_ontology_get_display_field            (TrackerField   *field);
+gboolean           tracker_ontology_field_is_child_of            (const gchar    *child,
+								  const gchar    *parent);
+TrackerField *     tracker_ontology_get_field_def                (const gchar    *name);
+const gchar *      tracker_ontology_get_field_id                 (const gchar    *name);
 
 G_END_DECLS
 

Modified: branches/indexer-split/src/libtracker-common/tracker-parser.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-parser.c	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-parser.c	Thu Aug 21 17:33:36 2008
@@ -446,122 +446,6 @@
 	return NULL;
 }
 
-TrackerParser *
-tracker_parser_new (TrackerLanguage *language,
-		    gint max_word_length,
-		    gint min_word_length)
-{
-
-
-	TrackerParser *parser = g_new0 (TrackerParser, 1);
-
-	parser->language = language;
-	parser->max_word_length = max_word_length;
-	parser->min_word_length = min_word_length;
-
-	parser->attrs = NULL;
-
-	return parser;
-}
-
-void
-tracker_parser_reset (TrackerParser *parser,
-		      const gchar   *txt,
-		      gint           txt_size,
-		      gboolean       delimit_words,
-		      gboolean       enable_stemmer,
-		      gboolean       enable_stop_words)
-{
-        g_return_if_fail (parser != NULL);
-	g_return_if_fail (txt != NULL);
-
-	g_free (parser->attrs);
-
-	parser->enable_stemmer = enable_stemmer;
-	parser->enable_stop_words = enable_stop_words;
-	parser->delimit_words = delimit_words;
-	parser->encoding = get_encoding (txt);
-	parser->txt_size = txt_size;
-	parser->txt = txt;
-
-	parser->word_position = 0;
-
-	parser->cursor = txt;
-
-	if (parser->encoding == TRACKER_PARSER_ENCODING_CJK) {
-		PangoLogAttr *attrs;
-
-                parser->attr_length = g_utf8_strlen (parser->txt, parser->txt_size) + 1;
-
-		attrs = g_new0 (PangoLogAttr, parser->attr_length);
-
-		pango_get_log_attrs (parser->txt,
-                                     txt_size,
-                                     0,
-                                     pango_language_from_string ("C"),
-                                     attrs,
-                                     parser->attr_length);
-
-                parser->attrs = attrs;
-                parser->attr_pos = 0;
-	}
-}
-
-gchar *
-tracker_parser_process_word (TrackerParser *parser,
-                             const char    *word,
-                             gint           length,
-                             gboolean       do_strip)
-{
-	const gchar *stem_word;
-	gchar       *str = NULL;
-        gchar       *stripped_word = NULL;
-	guint        bytes, len;
-
-	if (word) {
-		if (length == -1) {
-			bytes = strlen (word);
-		} else {
-			bytes = length;
-		}
-
-		if (do_strip && get_encoding (word) == TRACKER_PARSER_ENCODING_LATIN) {
-        	        stripped_word = strip_word (word, bytes, &len);
-        	} else {
-        	        stripped_word = NULL;
-        	}
-
-                if (!stripped_word) {
-                        str = g_utf8_normalize (word,
-                                                bytes,
-                                                G_NORMALIZE_NFC);
-                } else {
-                        str = g_utf8_normalize (stripped_word,
-                                                len,
-                                                G_NORMALIZE_NFC);
-                        g_free (stripped_word);
-                }
-
-                if (!parser->enable_stemmer) {
-                	return str;
-                }
-
-                len = strlen (str);
-
-                stem_word = tracker_language_stem_word (parser->language, str, len);
-
-		if (stem_word) {
-			gchar *result;
-
-                        result = g_strdup (stem_word);
-       	        g_free (str);
-
-			return result;
-		}
-	}
-
-	return str;
-}
 
 static gchar *
 parser_next (TrackerParser *parser,
@@ -761,6 +645,176 @@
 
 }
 
+static gboolean
+word_table_increment (GHashTable *word_table,
+                      gchar      *index_word,
+                      gint        weight,
+                      gint        total_words,
+                      gint        max_words_to_index)
+{
+        gboolean update_count;
+
+        update_count = total_words <= max_words_to_index;
+
+        if (update_count) {
+                gpointer p;
+                gint     count;
+
+                p = g_hash_table_lookup (word_table, index_word);
+                count = GPOINTER_TO_INT (p);
+
+                g_hash_table_replace (word_table,
+                                      index_word,
+                                      GINT_TO_POINTER (count + weight));
+        } else {
+                g_free (index_word);
+        }
+
+        return update_count;
+}
+
+TrackerParser *
+tracker_parser_new (TrackerLanguage *language,
+		    gint             max_word_length,
+		    gint             min_word_length)
+{
+	TrackerParser *parser;
+
+        g_return_val_if_fail (TRACKER_IS_LANGUAGE (language), NULL);
+        g_return_val_if_fail (min_word_length > 0, NULL);
+        g_return_val_if_fail (min_word_length < max_word_length, NULL);
+
+        parser = g_new0 (TrackerParser, 1);
+
+	parser->language = g_object_ref (language);
+
+	parser->max_word_length = max_word_length;
+	parser->min_word_length = min_word_length;
+
+	parser->attrs = NULL;
+
+	return parser;
+}
+
+void
+tracker_parser_free (TrackerParser *parser)
+{
+        g_return_if_fail (parser != NULL);
+
+        if (parser->language) {
+                g_object_unref (parser->language);
+        }
+
+        g_free (parser->attrs);
+
+	g_free (parser);
+}
+
+void
+tracker_parser_reset (TrackerParser *parser,
+		      const gchar   *txt,
+		      gint           txt_size,
+		      gboolean       delimit_words,
+		      gboolean       enable_stemmer,
+		      gboolean       enable_stop_words)
+{
+        g_return_if_fail (parser != NULL);
+	g_return_if_fail (txt != NULL);
+
+	g_free (parser->attrs);
+
+	parser->enable_stemmer = enable_stemmer;
+	parser->enable_stop_words = enable_stop_words;
+	parser->delimit_words = delimit_words;
+	parser->encoding = get_encoding (txt);
+	parser->txt_size = txt_size;
+	parser->txt = txt;
+
+	parser->word_position = 0;
+
+	parser->cursor = txt;
+
+	if (parser->encoding == TRACKER_PARSER_ENCODING_CJK) {
+		PangoLogAttr *attrs;
+
+                parser->attr_length = g_utf8_strlen (parser->txt, parser->txt_size) + 1;
+
+		attrs = g_new0 (PangoLogAttr, parser->attr_length);
+
+		pango_get_log_attrs (parser->txt,
+                                     txt_size,
+                                     0,
+                                     pango_language_from_string ("C"),
+                                     attrs,
+                                     parser->attr_length);
+
+                parser->attrs = attrs;
+                parser->attr_pos = 0;
+	}
+}
+
+gchar *
+tracker_parser_process_word (TrackerParser *parser,
+                             const char    *word,
+                             gint           length,
+                             gboolean       do_strip)
+{
+	const gchar *stem_word;
+	gchar       *str;
+        gchar       *stripped_word;
+	guint        bytes, len;
+
+        g_return_val_if_fail (parser != NULL, NULL);
+        g_return_val_if_fail (word != NULL, NULL);
+
+        str = NULL;
+        stripped_word = NULL;
+
+	if (word) {
+		if (length == -1) {
+			bytes = strlen (word);
+		} else {
+			bytes = length;
+		}
+
+		if (do_strip && get_encoding (word) == TRACKER_PARSER_ENCODING_LATIN) {
+        	        stripped_word = strip_word (word, bytes, &len);
+        	} else {
+        	        stripped_word = NULL;
+        	}
+
+                if (!stripped_word) {
+                        str = g_utf8_normalize (word,
+                                                bytes,
+                                                G_NORMALIZE_NFC);
+                } else {
+                        str = g_utf8_normalize (stripped_word,
+                                                len,
+                                                G_NORMALIZE_NFC);
+                        g_free (stripped_word);
+                }
+
+                if (!parser->enable_stemmer) {
+                	return str;
+                }
+
+                len = strlen (str);
+
+                stem_word = tracker_language_stem_word (parser->language, str, len);
+
+		if (stem_word) {
+			gchar *result;
+
+                        result = g_strdup (stem_word);
+       	        g_free (str);
+
+			return result;
+		}
+	}
+
+	return str;
+}
+
 gboolean
 tracker_parser_is_stop_word (TrackerParser *parser, const gchar *word)
 {
@@ -775,29 +829,25 @@
 
 gchar *
 tracker_parser_next (TrackerParser *parser,
-		     guint *position,
-		     guint *byte_offset_start,
-		     guint *byte_offset_end,
-		     gboolean *new_paragraph,
-		     gboolean *stop_word)
-{
-
-	guint byte_start, byte_end;
-	gboolean new_para;
-	char *str;
-
-
+		     guint         *position,
+		     guint         *byte_offset_start,
+		     guint         *byte_offset_end,
+		     gboolean      *new_paragraph,
+		     gboolean      *stop_word)
+{
+	gchar    *str;
+	guint     byte_start, byte_end;
+	gboolean  new_para;
 
 	if (parser->encoding == TRACKER_PARSER_ENCODING_CJK) {
 		str = pango_next (parser, 0, &byte_start, &byte_end, &new_para);
-
 		parser->word_position++;
 
-		*stop_word = FALSE;
-
+                *stop_word = FALSE;
 	} else {
 		str = parser_next (parser, 0, &byte_start, &byte_end, &new_para);
 		parser->word_position++;
+
 		if (parser->enable_stop_words && is_stop_word (parser->language, str)) {
 			*stop_word = TRUE;
 		} else {
@@ -811,38 +861,29 @@
 	*new_paragraph = new_para;
 
 	return str;
-
 }
 
 void
 tracker_parser_set_posititon (TrackerParser *parser,
-		     	      guint position)
+		     	      guint          position)
 {
-	guint byte_start, byte_end;
-	gboolean para;
+        gchar    *s;
+	guint     byte_start, byte_end;
+	gboolean  para;
 
+        g_return_if_fail (parser != NULL);
 
 	parser->word_position = 0;
 	parser->cursor = parser->txt;
 	parser->attr_pos = 0;
 
 	if (parser->encoding == TRACKER_PARSER_ENCODING_CJK) {
-		char *s = pango_next (parser, position, &byte_start, &byte_end, &para);
+                s = pango_next (parser, position, &byte_start, &byte_end, &para);
 		g_free (s);
 	} else {
-		char *s = parser_next (parser, position, &byte_start, &byte_end, &para);
+		s = parser_next (parser, position, &byte_start, &byte_end, &para);
 		g_free (s);
 	}
-
-}
-
-void
-tracker_parser_free (TrackerParser *parser)
-{
-	if (parser->attrs) g_free (parser->attrs);
-
-	g_free (parser);
-
 }
 
 gchar *
@@ -854,7 +895,7 @@
                                gboolean         filter_numbers,
                                gboolean         delimit)
 {
-	const gchar *p = txt;
+	const gchar *p;
 	gchar       *parsed_text;
 	guint32      i = 0;
         gint         len;
@@ -865,6 +906,7 @@
                 return NULL;
         }
 
+        p = txt;
         len = strlen (txt);
         len = MIN (len, 500);
 
@@ -973,7 +1015,7 @@
 	gchar  *s;
 	gchar **strv;
 
-        g_return_val_if_fail (language != NULL, NULL);
+        g_return_val_if_fail (TRACKER_IS_LANGUAGE (language), NULL);
 
         s = tracker_parser_text_to_string (text,
                                            language,
@@ -993,10 +1035,8 @@
                           const gchar *txt,
                           gint         weight)
 {
-	gchar    **tmp;
-	gchar    **array;
-	gpointer   k = 0;
-        gpointer   v = 0;
+	gchar **array;
+	gchar **p;
 
         /* Use this for already processed text only */
 	if (!word_table) {
@@ -1011,57 +1051,19 @@
 	}
 
 	array = g_strsplit (txt, " ", -1);
+        if (!array) {
+                return word_table;
+        }
 
-	for (tmp = array; *tmp; tmp++) {
-		if (!(**tmp)) {
-                        continue;
-                }
-
-                if (!g_hash_table_lookup_extended (word_table, *tmp, &k, &v)) {
-                        g_hash_table_insert (word_table,
-                                             g_strdup (*tmp),
-                                             GINT_TO_POINTER (GPOINTER_TO_INT (v) + weight));
-                } else {
-                        g_hash_table_insert (word_table,
-                                             *tmp,
-                                             GINT_TO_POINTER (GPOINTER_TO_INT (v) + weight));
-                }
+	for (p = array; *p; p++) {
+                word_table_increment (word_table, *p, weight, 0, 0);
 	}
 
-	g_strfreev (array);
-
+        g_free (array);
+        
 	return word_table;
 }
 
-static gboolean
-word_table_increment (GHashTable *word_table,
-                      gchar      *index_word,
-                      gint        weight,
-                      gint        total_words,
-                      gint        max_words_to_index)
-{
-        gboolean update_count;
-
-        update_count = total_words <= max_words_to_index;
-
-        if (update_count) {
-                gpointer p;
-                gint     count;
-
-                p = g_hash_table_lookup (word_table, index_word);
-                count = GPOINTER_TO_INT (p);
-
-                g_hash_table_replace (word_table,
-                                      index_word,
-                                      GINT_TO_POINTER (count + weight));
-        } else {
-                g_free (index_word);
-        }
-
-        return update_count;
-}
-
-
 GHashTable *
 tracker_parser_text (GHashTable      *word_table,
                      const gchar     *txt,
@@ -1079,7 +1081,7 @@
         /* Use this for unprocessed raw text */
 	gint         total_words;
 
-        g_return_val_if_fail (language != NULL, NULL);
+        g_return_val_if_fail (TRACKER_IS_LANGUAGE (language), NULL);
 
 	if (!word_table) {
 		word_table = g_hash_table_new_full (g_str_hash,

Modified: branches/indexer-split/src/libtracker-common/tracker-service.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-service.c	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-service.c	Thu Aug 21 17:33:36 2008
@@ -86,6 +86,9 @@
 
 	if (etype == 0) {
 		static const GEnumValue values[] = {
+			{ TRACKER_DB_TYPE_UNKNOWN, 
+			  "TRACKER_DB_TYPE_UNKNOWN", 
+			  "unknown" },
 			{ TRACKER_DB_TYPE_DATA, 
 			  "TRACKER_DB_TYPE_DATA", 
 			  "data" },
@@ -101,6 +104,12 @@
 			{ TRACKER_DB_TYPE_EMAIL, 
 			  "TRACKER_DB_TYPE_EMAIL", 
 			  "email" },
+			{ TRACKER_DB_TYPE_FILES, 
+			  "TRACKER_DB_TYPE_FILES", 
+			  "files" },
+			{ TRACKER_DB_TYPE_XESAM, 
+			  "TRACKER_DB_TYPE_XESAM", 
+			  "xesam" },
 			{ TRACKER_DB_TYPE_CACHE, 
 			  "TRACKER_DB_TYPE_CACHE", 
 			  "cache" },

Modified: branches/indexer-split/src/libtracker-common/tracker-service.h
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-service.h	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-service.h	Thu Aug 21 17:33:36 2008
@@ -29,6 +29,7 @@
 #define TRACKER_TYPE_DB_TYPE (tracker_db_type_get_type ())
 
 typedef enum {
+	TRACKER_DB_TYPE_UNKNOWN, 
 	TRACKER_DB_TYPE_DATA, 
 	TRACKER_DB_TYPE_INDEX,
 	TRACKER_DB_TYPE_COMMON, 

Modified: branches/indexer-split/src/libtracker-db/tracker-db-index-manager.c
==============================================================================
--- branches/indexer-split/src/libtracker-db/tracker-db-index-manager.c	(original)
+++ branches/indexer-split/src/libtracker-db/tracker-db-index-manager.c	Thu Aug 21 17:33:36 2008
@@ -25,14 +25,12 @@
 #include <gio/gio.h>
 
 #include <libtracker-common/tracker-file-utils.h>
+#include <libtracker-common/tracker-ontology.h>
 
 #include "tracker-db-index-manager.h"
 
-#define MIN_BUCKET_DEFAULT 10
-#define MAX_BUCKET_DEFAULT 20
-
-#define TRACKER_DB_INDEX_FILENAME         "index.db"
-#define TRACKER_DB_INDEX_UPDATE_FILENAME  "index-update.db"
+#define MIN_BUCKET_DEFAULT  10
+#define MAX_BUCKET_DEFAULT  20
 
 #define MAX_INDEX_FILE_SIZE 2000000000
 
@@ -44,19 +42,29 @@
         gchar              *abs_filename;
 } TrackerDBIndexDefinition;
 
-static gboolean                 initialized;
-static gchar                   *data_dir;
+static gboolean                  initialized;
+static gchar                    *data_dir;
 
-static TrackerDBIndexDefinition indexes[] = {
-        { TRACKER_DB_INDEX_TYPE_INDEX, 
+static TrackerDBIndexDefinition  indexes[] = {
+        { TRACKER_DB_INDEX_UNKNOWN, 
+	  NULL,
+          NULL,
+          NULL,
+          NULL },
+        { TRACKER_DB_INDEX_FILE, 
+	  NULL,
+          "file-index.db",
+          "file-index",
+          NULL },
+        { TRACKER_DB_INDEX_FILE_UPDATE, 
 	  NULL,
-          TRACKER_DB_INDEX_FILENAME,
-          "index",
+          "file-index-update.db",
+          "file-index-update",
           NULL },
-        { TRACKER_DB_INDEX_TYPE_INDEX_UPDATE, 
+        { TRACKER_DB_INDEX_EMAIL, 
 	  NULL,
-          TRACKER_DB_INDEX_UPDATE_FILENAME,
-          "index-update",
+          "email-index.db",
+          "email-index",
           NULL }
 };
 
@@ -71,11 +79,11 @@
 	gchar           *dirname;
 	gboolean         found;
 
-	if (type != TRACKER_DB_INDEX_TYPE_INDEX) {
+	if (type == TRACKER_DB_INDEX_UNKNOWN) {
 		return FALSE;
 	}
 
-	prefix = g_strconcat (indexes[TRACKER_DB_INDEX_TYPE_INDEX].name, ".tmp", NULL);
+	prefix = g_strconcat (indexes[type].name, ".tmp", NULL);
 
 	dirname = g_path_get_dirname (indexes[type].abs_filename);
 	file = g_file_new_for_path (dirname);
@@ -160,7 +168,7 @@
 
 	g_message ("Checking index files exist");
 
-	for (i = 0; i < G_N_ELEMENTS (indexes); i++) {
+	for (i = 1; i < G_N_ELEMENTS (indexes); i++) {
 		indexes[i].abs_filename = g_build_filename (data_dir, indexes[i].file, NULL);
 
 		if (need_reindex) {
@@ -174,7 +182,23 @@
 	
 	g_message ("Merging old temporary indexes");
 	
-	i = TRACKER_DB_INDEX_TYPE_INDEX;
+	i = TRACKER_DB_INDEX_FILE;
+	name = g_strconcat (indexes[i].name, "-final", NULL);
+	final_index_filename = g_build_filename (data_dir, name, NULL);
+	g_free (name);
+	
+	if (g_file_test (final_index_filename, G_FILE_TEST_EXISTS) && 
+	    !has_tmp_merge_files (i)) {
+		g_message ("  Overwriting '%s' with '%s'", 
+			   indexes[i].abs_filename, 
+			   final_index_filename);	
+		
+		g_rename (final_index_filename, indexes[i].abs_filename);
+	}
+	
+	g_free (final_index_filename);
+
+	i = TRACKER_DB_INDEX_EMAIL;
 	name = g_strconcat (indexes[i].name, "-final", NULL);
 	final_index_filename = g_build_filename (data_dir, name, NULL);
 	g_free (name);
@@ -199,7 +223,7 @@
 	if (force_reindex || need_reindex) {
 		g_message ("Cleaning up index files for reindex");
 
-		for (i = 0; i < G_N_ELEMENTS (indexes); i++) {
+		for (i = 1; i < G_N_ELEMENTS (indexes); i++) {
 			g_unlink (indexes[i].abs_filename);
 		}
 	}
@@ -208,7 +232,7 @@
 	
 	readonly = (flags & TRACKER_DB_INDEX_MANAGER_READONLY) != 0;
 
-	for (i = 0; i < G_N_ELEMENTS (indexes); i++) {
+	for (i = 1; i < G_N_ELEMENTS (indexes); i++) {
 		indexes[i].index = tracker_db_index_new (indexes[i].abs_filename,
 							 min_bucket, 
 							 max_bucket, 
@@ -229,7 +253,7 @@
                 return;
         }
         
-	for (i = 0; i < G_N_ELEMENTS (indexes); i++) {
+	for (i = 1; i < G_N_ELEMENTS (indexes); i++) {
 		g_object_unref (indexes[i].index);
 		indexes[i].index = NULL;
 
@@ -248,6 +272,70 @@
 	return indexes[type].index;
 }
 
+TrackerDBIndex *
+tracker_db_index_manager_get_index_by_service (const gchar *service)
+{
+	TrackerDBType      type;
+	TrackerDBIndexType index_type;
+
+	g_return_val_if_fail (initialized == TRUE, NULL);
+	g_return_val_if_fail (service != NULL, NULL);
+
+	type = tracker_ontology_get_db_by_service_type (service);
+
+	switch (type) {
+	case TRACKER_DB_TYPE_FILES:
+		index_type = TRACKER_DB_INDEX_FILE;
+		break;
+	case TRACKER_DB_TYPE_EMAIL:
+		index_type = TRACKER_DB_INDEX_EMAIL;
+		break;
+	default:
+		/* How do we handle XESAM? and others? default to files? */
+		index_type = TRACKER_DB_INDEX_UNKNOWN;
+		break;
+	}
+
+	return indexes[index_type].index;
+}
+
+TrackerDBIndex *
+tracker_db_index_manager_get_index_by_service_id (gint id)
+{
+	TrackerDBType       type;
+	TrackerDBIndexType  index_type;
+	gchar              *service;
+
+	g_return_val_if_fail (initialized == TRUE, NULL);
+
+	service = tracker_ontology_get_service_type_by_id (id);
+	if (!service) {
+		return NULL;
+	}
+
+	type = tracker_ontology_get_db_by_service_type (service);
+	g_free (service);
+
+	switch (type) {
+	case TRACKER_DB_TYPE_FILES:
+		index_type = TRACKER_DB_INDEX_FILE;
+		break;
+	case TRACKER_DB_TYPE_EMAIL:
+		index_type = TRACKER_DB_INDEX_EMAIL;
+		break;
+	default:
+		/* How do we handle XESAM? and others? default to files? */
+		index_type = TRACKER_DB_INDEX_UNKNOWN;
+		break;
+	}
+
+	if (index_type == TRACKER_DB_INDEX_UNKNOWN) {
+		return NULL;
+	}
+
+	return indexes[index_type].index;
+}
+
 const gchar *
 tracker_db_index_manager_get_filename (TrackerDBIndexType type)
 {
@@ -262,7 +350,7 @@
 
 	g_return_val_if_fail (initialized == TRUE, FALSE);
 
-	for (i = 0, too_big = FALSE; i < G_N_ELEMENTS (indexes) && !too_big; i++) {
+	for (i = 1, too_big = FALSE; i < G_N_ELEMENTS (indexes) && !too_big; i++) {
 		too_big = tracker_file_get_size (indexes[i].abs_filename) > MAX_INDEX_FILE_SIZE;
 	}
         

Modified: branches/indexer-split/src/libtracker-db/tracker-db-index-manager.h
==============================================================================
--- branches/indexer-split/src/libtracker-db/tracker-db-index-manager.h	(original)
+++ branches/indexer-split/src/libtracker-db/tracker-db-index-manager.h	Thu Aug 21 17:33:36 2008
@@ -29,8 +29,10 @@
 #include "tracker-db-index.h"
 
 typedef enum {
-	TRACKER_DB_INDEX_TYPE_INDEX,
-	TRACKER_DB_INDEX_TYPE_INDEX_UPDATE
+	TRACKER_DB_INDEX_UNKNOWN,
+	TRACKER_DB_INDEX_FILE,
+	TRACKER_DB_INDEX_FILE_UPDATE,
+	TRACKER_DB_INDEX_EMAIL
 } TrackerDBIndexType;
 
 typedef enum {
@@ -38,13 +40,15 @@
 	TRACKER_DB_INDEX_MANAGER_READONLY      = 1 << 2
 } TrackerDBIndexManagerFlags;
 
-gboolean        tracker_db_index_manager_init                (TrackerDBIndexManagerFlags  flags,
-							      gint                        min_bucket,
-							      gint                        max_bucket);
-void            tracker_db_index_manager_shutdown            (void);
-const gchar *   tracker_db_index_manager_get_filename        (TrackerDBIndexType          index);
-TrackerDBIndex *tracker_db_index_manager_get_index           (TrackerDBIndexType          index);
-gboolean        tracker_db_index_manager_are_indexes_too_big (void);
+gboolean        tracker_db_index_manager_init                    (TrackerDBIndexManagerFlags  flags,
+								  gint                        min_bucket,
+								  gint                        max_bucket);
+void            tracker_db_index_manager_shutdown                (void);
+TrackerDBIndex *tracker_db_index_manager_get_index               (TrackerDBIndexType          index);
+TrackerDBIndex *tracker_db_index_manager_get_index_by_service    (const gchar                *service);
+TrackerDBIndex *tracker_db_index_manager_get_index_by_service_id (gint                        id);
+const gchar *   tracker_db_index_manager_get_filename            (TrackerDBIndexType          index);
+gboolean        tracker_db_index_manager_are_indexes_too_big     (void);
 
 G_END_DECLS
 

Modified: branches/indexer-split/src/libtracker-db/tracker-db-manager.c
==============================================================================
--- branches/indexer-split/src/libtracker-db/tracker-db-manager.c	(original)
+++ branches/indexer-split/src/libtracker-db/tracker-db-manager.c	Thu Aug 21 17:33:36 2008
@@ -64,6 +64,16 @@
 } TrackerDBDefinition;
 
 static TrackerDBDefinition dbs[] = {
+	{ TRACKER_DB_UNKNOWN,
+	  TRACKER_DB_LOCATION_USER_DATA_DIR,
+	  NULL,
+	  NULL,
+	  NULL,
+	  NULL,
+	  32,
+          TRACKER_DB_PAGE_SIZE_DEFAULT, 
+          FALSE,
+          FALSE },
         { TRACKER_DB_COMMON, 
           TRACKER_DB_LOCATION_USER_DATA_DIR, 
 	  NULL,
@@ -2143,7 +2153,6 @@
 		tracker_db_interface_end_transaction (iface);
 	}
 
-
 	/* Load static xesam data */
 	db_get_static_xesam_data (iface);
 
@@ -2154,9 +2163,12 @@
 db_interface_create (TrackerDB db)
 {
 	switch (db) {
+        case TRACKER_DB_UNKNOWN:
+		return NULL;
+
         case TRACKER_DB_COMMON:
 		return db_interface_get_common ();
-
+		
         case TRACKER_DB_CACHE:
 		return db_interface_get_cache ();
 
@@ -2190,7 +2202,7 @@
 
 	g_message ("Removing all database files");
 
-	for (i = 0; i < G_N_ELEMENTS (dbs); i++) {
+	for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
 		g_message ("Removing database:'%s'", 
 			   dbs[i].abs_filename);
 		g_unlink (dbs[i].abs_filename);
@@ -2297,7 +2309,7 @@
 
 	g_message ("Checking database files exist");
 
-        for (i = 0, need_reindex = FALSE; i < G_N_ELEMENTS (dbs); i++) {
+        for (i = 1, need_reindex = FALSE; i < G_N_ELEMENTS (dbs); i++) {
                 /* Fill absolute path for the database */
                 dir = location_to_directory (dbs[i].location);
 		dbs[i].abs_filename = g_build_filename (dir, dbs[i].file, NULL);
@@ -2364,7 +2376,7 @@
 		/* Now create the databases and close them */
 		g_message ("Creating database files, this may take a few moments...");
 
-		for (i = 0; i < G_N_ELEMENTS (dbs); i++) {
+		for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
 			dbs[i].iface = db_interface_create (i);
 		}
 
@@ -2372,7 +2384,7 @@
 		 * becase some databases need other databases
 		 * attached to be created correctly.
 		 */
-		for (i = 0; i < G_N_ELEMENTS (dbs); i++) {
+		for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
 			g_object_unref (dbs[i].iface);
 			dbs[i].iface = NULL;
 		}
@@ -2395,7 +2407,7 @@
 	/* Load databases */
 	g_message ("Loading databases files...");
 
-	for (i = 0; i < G_N_ELEMENTS (dbs); i++) {
+	for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
 		dbs[i].iface = db_interface_create (i);
 	}
 
@@ -2411,7 +2423,7 @@
                 return;
         }
 
-        for (i = 0; i < G_N_ELEMENTS (dbs); i++) {
+        for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
                 if (dbs[i].abs_filename) {
                         g_free (dbs[i].abs_filename);
 			dbs[i].abs_filename = NULL;
@@ -2562,7 +2574,7 @@
 	g_return_val_if_fail (initialized != FALSE, NULL);
 	g_return_val_if_fail (service != NULL, NULL);
 
-	type = tracker_ontology_get_db_for_service_type (service);
+	type = tracker_ontology_get_db_by_service_type (service);
 
 	switch (type) {
 	case TRACKER_DB_TYPE_EMAIL:
@@ -2615,12 +2627,12 @@
 					     TrackerDBContentType  content_type)
 {
 	TrackerDBType type;
-	TrackerDB db;
+	TrackerDB     db;
 
 	g_return_val_if_fail (initialized != FALSE, NULL);
 	g_return_val_if_fail (service != NULL, NULL);
 
-	type = tracker_ontology_get_db_for_service_type (service);
+	type = tracker_ontology_get_db_by_service_type (service);
 
 	switch (type) {
 	case TRACKER_DB_TYPE_EMAIL:

Modified: branches/indexer-split/src/libtracker-db/tracker-db-manager.h
==============================================================================
--- branches/indexer-split/src/libtracker-db/tracker-db-manager.h	(original)
+++ branches/indexer-split/src/libtracker-db/tracker-db-manager.h	Thu Aug 21 17:33:36 2008
@@ -30,6 +30,7 @@
 #define TRACKER_TYPE_DB (tracker_db_get_type ())
 
 typedef enum {
+	TRACKER_DB_UNKNOWN,
         TRACKER_DB_COMMON,
         TRACKER_DB_CACHE,
         TRACKER_DB_FILE_METADATA,

Modified: branches/indexer-split/src/tracker-indexer/tracker-indexer.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-indexer.c	(original)
+++ branches/indexer-split/src/tracker-indexer/tracker-indexer.c	Thu Aug 21 17:33:36 2008
@@ -107,7 +107,8 @@
 
 	gchar *db_dir;
 
-	TrackerDBIndex *index;
+	TrackerDBIndex *file_index;
+	TrackerDBIndex *email_index;
 
 	TrackerDBInterface *file_metadata;
 	TrackerDBInterface *file_contents;
@@ -144,8 +145,6 @@
 };
 
 struct MetadataForeachData {
-	TrackerDBIndex *index;
-
 	TrackerLanguage *language;
 	TrackerConfig *config;
 	TrackerService *service;
@@ -153,8 +152,6 @@
 };
 
 struct UpdateWordsForeachData {
-	TrackerDBIndex *index;
-
 	guint32 service_id;
 	guint32 service_type_id;
 };
@@ -291,7 +288,8 @@
 		stop_transaction (indexer);
 	}
 
-	tracker_db_index_flush (indexer->private->index);
+	tracker_db_index_flush (indexer->private->file_index);
+	tracker_db_index_flush (indexer->private->email_index);
 	signal_status (indexer, "flush");
 
 	indexer->private->items_processed = 0;
@@ -428,7 +426,8 @@
 	g_object_unref (priv->language);
 	g_object_unref (priv->config);
 
-	g_object_unref (priv->index);
+	g_object_unref (priv->file_index);
+	g_object_unref (priv->email_index);
 
 	g_free (priv->db_dir);
 
@@ -784,8 +783,11 @@
 	}
 
 	/* Set up indexer */
-	index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_TYPE_INDEX);
-	priv->index = g_object_ref (index);
+	index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_FILE);
+	priv->file_index = g_object_ref (index);
+
+	index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_EMAIL);
+	priv->email_index = g_object_ref (index);
 
 	/* Set up databases, these pointers are mostly used to
 	 * start/stop transactions, since TrackerDBManager treats
@@ -833,8 +835,10 @@
 		     const gchar         *value,
 		     MetadataForeachData *data)
 {
+	TrackerDBIndex *index;
 	gchar *parsed_value;
 	gchar **arr;
+	gint service_id;
 	gint i;
 
 	parsed_value = tracker_parser_text_to_string (value,
@@ -850,12 +854,14 @@
 	}
 
 	arr = g_strsplit (parsed_value, " ", -1);
+	service_id = tracker_service_get_id (data->service);
+	index = tracker_db_index_manager_get_index_by_service_id (service_id);
 
 	for (i = 0; arr[i]; i++) {
-		tracker_db_index_add_word (data->index,
+		tracker_db_index_add_word (index,
 					   arr[i],
 					   data->id,
-					   tracker_service_get_id (data->service),
+					   service_id,
 					   tracker_field_get_weight (field));
 	}
 
@@ -907,7 +913,6 @@
 {
 	MetadataForeachData data;
 
-	data.index = indexer->private->index;
 	data.language = indexer->private->language;
 	data.config = indexer->private->config;
 	data.service = service;
@@ -926,6 +931,7 @@
 		    gboolean        full_parsing,
 		    gint            weight_factor)
 {
+	TrackerDBIndex *index;
 	GHashTable     *parsed;
 	GHashTableIter  iter;
 	gpointer        key, value;
@@ -954,9 +960,11 @@
 	}
 
 	g_hash_table_iter_init (&iter, parsed);
+
+	index = tracker_db_index_manager_get_index_by_service_id (service_type);
 	
 	while (g_hash_table_iter_next (&iter, &key, &value)) {
-		tracker_db_index_add_word (indexer->private->index,
+		tracker_db_index_add_word (index,
 					   key,
 					   service_id,
 					   service_type,
@@ -1031,8 +1039,9 @@
 		     gpointer value, 
 		     gpointer user_data)
 {
-	gchar                  *word;
+	TrackerDBIndex         *index;
 	UpdateWordsForeachData *data;
+	gchar                  *word;
 	gint                    score;
 
 	word = key;
@@ -1040,7 +1049,9 @@
 
 	data = user_data;
 
-	tracker_db_index_add_word (data->index,
+	index = tracker_db_index_manager_get_index_by_service_id (data->service_type_id);
+
+	tracker_db_index_add_word (index,
 				   word,
 				   data->service_id,
 				   data->service_type_id,
@@ -1055,7 +1066,6 @@
 {
 	UpdateWordsForeachData user_data;
 
-	user_data.index = indexer->private->index;
 	user_data.service_id = service_id;
 	user_data.service_type_id = service_type_id;
 
@@ -1809,7 +1819,8 @@
 		indexer->private->idle_id = 0;
 		indexer->private->is_paused = TRUE;
 
-		tracker_db_index_close (indexer->private->index);
+		tracker_db_index_close (indexer->private->file_index);
+		tracker_db_index_close (indexer->private->email_index);
 		g_signal_emit (indexer, signals[PAUSED], 0);
 	} else {
 		check_disk_space_start (indexer);
@@ -1818,7 +1829,8 @@
 		indexer->private->is_paused = FALSE;
 		indexer->private->idle_id = g_idle_add (process_func, indexer);
 
-		tracker_db_index_open (indexer->private->index);
+		tracker_db_index_open (indexer->private->file_index);
+		tracker_db_index_open (indexer->private->email_index);
 		g_signal_emit (indexer, signals[CONTINUED], 0);
 	}
 }

Modified: branches/indexer-split/src/trackerd/tracker-db.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-db.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-db.c	Thu Aug 21 17:33:36 2008
@@ -38,6 +38,7 @@
 
 #include <libtracker-db/tracker-db-index.h>
 #include <libtracker-db/tracker-db-interface-sqlite.h>
+#include <libtracker-db/tracker-db-index-manager.h>
 #include <libtracker-db/tracker-db-manager.h>
 
 #include "tracker-db.h"
@@ -48,11 +49,31 @@
 
 #define ZLIBBUFSIZ 8192
 
-static gboolean         initialized;
+typedef struct {
+	TrackerConfig   *config;
+	TrackerLanguage *language;
+} TrackerDBPrivate;
 
-static TrackerConfig   *config;
-static TrackerLanguage *language;
-static TrackerDBIndex  *db_index;
+/* Private */
+static GStaticPrivate private_key = G_STATIC_PRIVATE_INIT;
+
+static void
+private_free (gpointer data)
+{
+	TrackerDBPrivate *private;
+
+	private = data;
+
+	if (private->config) {
+		g_object_unref (private->config);
+	}
+
+	if (private->language) {
+		g_object_unref (private->language);
+	}
+
+	g_free (private);
+}
 
 static gchar *
 compress_string (const gchar *ptr, 
@@ -221,12 +242,16 @@
 		       const gchar  *old_value, 
 		       const gchar  *new_value) 
 {
-	GHashTable *old_table;
-	GHashTable *new_table;
-	gint        sid;
+	TrackerDBPrivate *private;
+	GHashTable       *old_table;
+	GHashTable       *new_table;
+	gint              sid;
 
 	g_return_if_fail (TRACKER_IS_FIELD (def));
 
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
 	old_table = NULL;
 	new_table = NULL;
 
@@ -234,10 +259,10 @@
 		old_table = tracker_parser_text (old_table, 
 						 old_value, 
 						 tracker_field_get_weight (def), 
-						 language, 
- 						 tracker_config_get_max_words_to_index (config),
- 						 tracker_config_get_max_word_length (config),
- 						 tracker_config_get_min_word_length (config),
+						 private->language, 
+ 						 tracker_config_get_max_words_to_index (private->config),
+ 						 tracker_config_get_max_word_length (private->config),
+ 						 tracker_config_get_min_word_length (private->config),
 						 tracker_field_get_filtered (def), 
 						 tracker_field_get_delimited (def));
 	}
@@ -247,10 +272,10 @@
 		new_table = tracker_parser_text (new_table, 
 						 new_value, 
 						 tracker_field_get_weight (def), 
-						 language, 
- 						 tracker_config_get_max_words_to_index (config),
- 						 tracker_config_get_max_word_length (config),
- 						 tracker_config_get_min_word_length (config),
+						 private->language, 
+ 						 tracker_config_get_max_words_to_index (private->config),
+ 						 tracker_config_get_max_word_length (private->config),
+ 						 tracker_config_get_min_word_length (private->config),
 						 tracker_field_get_filtered (def), 
 						 tracker_field_get_delimited (def));
 	}
@@ -468,62 +493,120 @@
 	return id;
 }
 
-static GArray *
-db_create_array_of_services (void)
-{
-	GArray *array;
-	gint    services[8];
-	gint    count = 0;
-
-	/* FIXME: Shouldn't we add emails and GAIM conversaions? -mr */
-	services[count++] = tracker_ontology_get_id_for_service_type ("Folders");
-	services[count++] = tracker_ontology_get_id_for_service_type ("Documents");
-	services[count++] = tracker_ontology_get_id_for_service_type ("Images");
-	services[count++] = tracker_ontology_get_id_for_service_type ("Videos");
-	services[count++] = tracker_ontology_get_id_for_service_type ("Music");
-	services[count++] = tracker_ontology_get_id_for_service_type ("Text");
-	services[count++] = tracker_ontology_get_id_for_service_type ("Development");
-	services[count++] = tracker_ontology_get_id_for_service_type ("Other");
+GArray *
+tracker_db_create_array_of_services (const gchar *service,
+				     gboolean     basic_services)
+{
+	GArray   *array;
+	gint      services[12];
+	gint      count;
+	gboolean  add_files;
+	gboolean  add_emails;
+	gboolean  add_conversations;
+
+	if (service) {
+		if (g_ascii_strcasecmp (service, "Files") == 0) {
+			add_files = TRUE;
+			add_emails = FALSE;
+			add_conversations = FALSE;
+		} else if (g_ascii_strcasecmp (service, "Emails") == 0) {
+			add_files = FALSE;
+			add_emails = TRUE;
+			add_conversations = FALSE;
+		} else if (g_ascii_strcasecmp (service, "Conversations") == 0) {
+			add_files = FALSE;
+			add_emails = FALSE;
+			add_conversations = TRUE;
+		} else {
+			/* Maybe set them all to TRUE? */
+			add_files = FALSE;
+			add_emails = FALSE;
+			add_conversations = FALSE;
+		}
+	} else if (basic_services) {
+		add_files = TRUE;
+		add_emails = FALSE;
+		add_conversations = FALSE;
+	} else {
+		add_files = TRUE;
+		add_emails = TRUE;
+		add_conversations = TRUE;
+	}
+
+	count = 0;
+
+	if (add_files) {
+		services[count++] = tracker_ontology_get_id_for_service_type ("Folders");
+		services[count++] = tracker_ontology_get_id_for_service_type ("Documents");
+		services[count++] = tracker_ontology_get_id_for_service_type ("Images");
+		services[count++] = tracker_ontology_get_id_for_service_type ("Videos");
+		services[count++] = tracker_ontology_get_id_for_service_type ("Music");
+		services[count++] = tracker_ontology_get_id_for_service_type ("Text");
+		services[count++] = tracker_ontology_get_id_for_service_type ("Development");
+		services[count++] = tracker_ontology_get_id_for_service_type ("Other");
+	}
+
+	if (add_emails) {
+		services[count++] = tracker_ontology_get_id_for_service_type ("EvolutionEmails");
+		services[count++] = tracker_ontology_get_id_for_service_type ("KMailEmails");
+		services[count++] = tracker_ontology_get_id_for_service_type ("ThunderbirdEmails");
+	}
+	
+	if (add_conversations) {
+		services[count++] = tracker_ontology_get_id_for_service_type ("GaimConversations");
+	}
+
+	services[count] = 0;
 
 	array = g_array_new (TRUE, TRUE, sizeof (gint));
-	g_array_append_vals (array, services, G_N_ELEMENTS (services));
+	g_array_append_vals (array, services, count);
 
 	return array;
 }
 
 void
-tracker_db_init (TrackerConfig   *this_config,
-		 TrackerLanguage *this_language,
-		 TrackerDBIndex  *this_index)
-{
-	g_return_if_fail (TRACKER_IS_CONFIG (this_config));
-	g_return_if_fail (TRACKER_IS_LANGUAGE (this_language));
-	g_return_if_fail (TRACKER_IS_DB_INDEX (this_index));
-	
-	if (initialized) {
+tracker_db_init (TrackerConfig   *config,
+		 TrackerLanguage *language,
+		 TrackerDBIndex  *file_index,
+		 TrackerDBIndex  *email_index)
+{
+	TrackerDBPrivate *private;
+
+	g_return_if_fail (TRACKER_IS_CONFIG (config));
+	g_return_if_fail (TRACKER_IS_LANGUAGE (language));
+	g_return_if_fail (TRACKER_IS_DB_INDEX (file_index));
+	g_return_if_fail (TRACKER_IS_DB_INDEX (email_index));
+
+	private = g_static_private_get (&private_key);
+	if (private) {
+		g_warning ("Already initialized (%s)", 
+			   __FUNCTION__);
 		return;
 	}
 
-	config = g_object_ref (this_config);
-	language = g_object_ref (this_language);
-	db_index = g_object_ref (this_index);
+	private = g_new0 (TrackerDBPrivate, 1);
+	
+	private->config = g_object_ref (config);
+	private->language = g_object_ref (language);
+
+	g_static_private_set (&private_key, 
+			      private, 
+			      private_free);
 }
 
 void
 tracker_db_shutdown (void)
 {
-	if (!initialized) {
+	TrackerDBPrivate *private;
+
+	private = g_static_private_get (&private_key);
+	if (!private) {
+		g_warning ("Not initialized (%s)", 
+			   __FUNCTION__);
 		return;
 	}
 
-	g_object_unref (db_index);
-	db_index = NULL;
-
-	g_object_unref (language);
-	language = NULL;
-
-	g_object_unref (config);
-	config = NULL;
+	g_static_private_free (&private_key);
 }
 
 gboolean
@@ -630,6 +713,7 @@
 			gboolean            save_results, 
 			gboolean            detailed)
 {
+	TrackerDBPrivate    *private;
 	TrackerQueryTree    *tree;
 	TrackerDBResultSet  *result_set, *result;
 	gchar 		   **array;
@@ -647,10 +731,13 @@
 	g_return_val_if_fail (search_string != NULL, NULL);
 	g_return_val_if_fail (offset >= 0, NULL);
 
+	private = g_static_private_get (&private_key);
+	g_return_val_if_fail (private != NULL, NULL);
+
 	array = tracker_parser_text_into_array (search_string,
-						language,
-						tracker_config_get_max_word_length (config),
-						tracker_config_get_min_word_length (config));
+						private->language,
+						tracker_config_get_max_word_length (private->config),
+						tracker_config_get_min_word_length (private->config));
 
 	result_set = tracker_db_exec_proc (iface, 
 					   "GetRelatedServiceIDs", 
@@ -676,10 +763,10 @@
 		g_object_unref (result_set);
 	}
 
+	/* FIXME: Do we need both index and services here? We used to have it */
 	tree = tracker_query_tree_new (search_string, 
-				       db_index, 
-				       config,
-				       language,
+				       private->config,
+				       private->language,
 				       services);
 	hits = tracker_query_tree_get_hits (tree, offset, limit);
 	result = NULL;
@@ -785,14 +872,19 @@
 
 	/* Delete duds */
 	if (duds) {
-		TrackerDBIndex *index;
+		TrackerDBIndex *file_index;
+		TrackerDBIndex *email_index;
 		GSList         *words, *w;
 
 		words = tracker_query_tree_get_words (tree);
-		index = tracker_query_tree_get_index (tree);
+		file_index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_FILE);
+		email_index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_EMAIL);
 
 		for (w = words; w; w = w->next) {
-			tracker_db_index_remove_dud_hits (index, 
+			tracker_db_index_remove_dud_hits (file_index, 
+							  (const gchar *) w->data, 
+							  duds);
+			tracker_db_index_remove_dud_hits (email_index, 
 							  (const gchar *) w->data, 
 							  duds);
 		}
@@ -823,6 +915,7 @@
 				 const gchar         *text, 
 				 gchar              **mime_array)
 {
+	TrackerDBPrivate   *private;
 	TrackerQueryTree   *tree;
 	TrackerDBResultSet *result_set1;
 	GArray             *hits;
@@ -834,13 +927,15 @@
 	g_return_val_if_fail (text != NULL, NULL);
 	g_return_val_if_fail (mime_array != NULL, NULL);
 
+	private = g_static_private_get (&private_key);
+	g_return_val_if_fail (private != NULL, NULL);
+
 	result_set1 = NULL;
-	services = db_create_array_of_services ();
+	services = tracker_db_create_array_of_services (NULL, TRUE);
 
 	tree = tracker_query_tree_new (text, 
-				       db_index, 
-				       config,
-				       language,
+				       private->config,
+				       private->language,
 				       services);
 	hits = tracker_query_tree_get_hits (tree, 0, 0);
 
@@ -917,6 +1012,7 @@
 				     const gchar        *text, 
 				     const gchar        *location)
 {
+	TrackerDBPrivate   *private;
 	TrackerDBResultSet *result_set1;
 	TrackerQueryTree   *tree;
 	GArray             *hits;
@@ -929,14 +1025,16 @@
 	g_return_val_if_fail (text != NULL, NULL);
 	g_return_val_if_fail (location != NULL, NULL);
 
+	private = g_static_private_get (&private_key);
+	g_return_val_if_fail (private != NULL, NULL);
+
 	result_set1 = NULL;
 	location_prefix = g_strconcat (location, G_DIR_SEPARATOR_S, NULL);
-	services = db_create_array_of_services ();
+	services = tracker_db_create_array_of_services (NULL, TRUE);
 
 	tree = tracker_query_tree_new (text, 
-				       db_index, 
-				       config,
-				       language,
+				       private->config,
+				       private->language,
 				       services);
 	hits = tracker_query_tree_get_hits (tree, 0, 0);
 
@@ -949,9 +1047,9 @@
 
 		str_id = tracker_guint_to_string (rank.service_id);
 		result_set2 = tracker_db_exec_proc (iface, 
-						   "GetFileByID", 
-						   str_id, 
-						   NULL);
+						    "GetFileByID", 
+						    str_id, 
+						    NULL);
 		g_free (str_id);
 
 		if (result_set2) {
@@ -1015,6 +1113,7 @@
 					      gchar              **mime_array, 
 					      const gchar         *location)
 {
+	TrackerDBPrivate   *private;
 	TrackerDBResultSet *result_set1;
 	TrackerQueryTree   *tree;
 	GArray             *hits;
@@ -1027,14 +1126,16 @@
 	g_return_val_if_fail (text != NULL, NULL);
 	g_return_val_if_fail (location != NULL, NULL);
 
+	private = g_static_private_get (&private_key);
+	g_return_val_if_fail (private != NULL, NULL);
+
 	result_set1 = NULL;
 	location_prefix = g_strconcat (location, G_DIR_SEPARATOR_S, NULL);
-	services = db_create_array_of_services ();
+	services = tracker_db_create_array_of_services (NULL, TRUE);
 
 	tree = tracker_query_tree_new (text, 
-				       db_index, 
-				       config,
-				       language,
+				       private->config,
+				       private->language,
 				       services);
 	hits = tracker_query_tree_get_hits (tree, 0, 0);
 
@@ -1424,15 +1525,16 @@
 			 gchar              **values, 
 			 gboolean             do_backup)
 {
-	TrackerField *def;
-	gchar 	     *old_value = NULL;
-	gchar        *new_value = NULL;
-	gchar        *res_service;
-	gboolean      update_index;
-	gint	      key_field = 0;
-	guint         i;
-	guint         length;
-	GString      *str = NULL;
+	TrackerDBPrivate *private;
+	TrackerField     *def;
+	gchar 	         *old_value;
+	gchar            *new_value;
+	gchar            *res_service;
+	gboolean          update_index;
+	gint	          key_field;
+	guint             i;
+	guint             length;
+	GString          *str;
 	
 	g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
 	g_return_val_if_fail (service_type != NULL, NULL);
@@ -1440,6 +1542,9 @@
 	g_return_val_if_fail (key != NULL, NULL);
 	g_return_val_if_fail (values != NULL, NULL);
 
+	private = g_static_private_get (&private_key);
+	g_return_val_if_fail (private != NULL, NULL);
+
 	if (strcmp (service_id, "0") == 0) {
 		return NULL;
 	}
@@ -1457,6 +1562,11 @@
 		g_warning ("Service not found for service_id:'%s'", service_id);
 		return NULL;
 	}
+
+	old_value = NULL;
+	new_value = NULL;
+	key_field = 0;
+	str = NULL;
 	
 	length = g_strv_length (values);
 
@@ -1475,7 +1585,7 @@
 		old_value = tracker_db_metadata_get_delimited (iface, service_id, key);
 	}
 
-	/* delete old value if metadata does not support multiple values */
+	/* Delete old value if metadata does not support multiple values */
 	if (!tracker_field_get_multiple_values (def)) {
 		tracker_db_metadata_delete (iface, service_type, service_id, key, FALSE);
 	}
@@ -1536,9 +1646,9 @@
 			}
 
 			mvalue = tracker_parser_text_to_string (values[i], 
-								language,
-								tracker_config_get_max_word_length (config),
-								tracker_config_get_min_word_length (config),
+								private->language,
+								tracker_config_get_max_word_length (private->config),
+								tracker_config_get_min_word_length (private->config),
 								tracker_field_get_filtered (def),  
 								tracker_field_get_filtered (def), 
 								tracker_field_get_delimited (def));
@@ -1586,9 +1696,9 @@
 			}
 
 			mvalue = tracker_parser_text_to_string (values[i], 
-								language,
-								tracker_config_get_max_word_length (config),
-								tracker_config_get_min_word_length (config),
+								private->language,
+								tracker_config_get_max_word_length (private->config),
+								tracker_config_get_min_word_length (private->config),
 								tracker_field_get_filtered (def),  
 								tracker_field_get_filtered (def), 
 								tracker_field_get_delimited (def));
@@ -1753,19 +1863,23 @@
 				  const gchar        *key, 
 				  const gchar        *value) 
 {
-	TrackerField *def;
-	gchar        *old_value = NULL;
-	gchar        *new_value = NULL;
-	gchar        *mvalue;
-	gchar        *res_service;
-	gboolean      update_index;
-	gint          key_field;
+	TrackerDBPrivate *private;
+	TrackerField     *def;
+	gchar            *old_value;
+	gchar            *new_value;
+	gchar            *mvalue;
+	gchar            *res_service;
+	gboolean          update_index;
+	gint              key_field;
 
 	g_return_if_fail (TRACKER_IS_DB_INTERFACE (iface));
 	g_return_if_fail (service != NULL);
 	g_return_if_fail (id != NULL);
 	g_return_if_fail (key != NULL);
 
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
 	/* Get type details */
 	def = tracker_ontology_get_field_def (key);
 
@@ -1773,6 +1887,9 @@
 		return;
 	}
 
+	old_value = NULL;
+	new_value = NULL;
+
 	if (!tracker_field_get_embedded (def) && 
             tracker_ontology_service_type_has_embedded (service)) {
 		backup_delete_non_embedded_metadata_value (iface, 
@@ -1811,9 +1928,9 @@
 	case TRACKER_FIELD_TYPE_INDEX:
 	case TRACKER_FIELD_TYPE_STRING:
 		mvalue = tracker_parser_text_to_string (value, 
-							language,
-							tracker_config_get_max_word_length (config),
-							tracker_config_get_min_word_length (config),
+							private->language,
+							tracker_config_get_max_word_length (private->config),
+							tracker_config_get_min_word_length (private->config),
 							tracker_field_get_filtered (def),  
 							tracker_field_get_filtered (def), 
 							tracker_field_get_delimited (def));
@@ -2404,6 +2521,7 @@
 			   const gchar        *service,
 			   TrackerDBFileInfo  *info)
 {
+	TrackerDBPrivate   *private;
 	TrackerDBResultSet *result_set;
 	TrackerDBResultSet *result_set_proc;
 	gint	            i;
@@ -2426,6 +2544,9 @@
 	g_return_val_if_fail (info->uri[0], 0);
 	g_return_val_if_fail (service, 0);
 
+	private = g_static_private_get (&private_key);
+	g_return_val_if_fail (private != NULL, 0);
+
 	if (info->uri[0] == G_DIR_SEPARATOR) {
 		name = g_path_get_basename (info->uri);
 		path = g_path_get_dirname (info->uri);
@@ -2540,7 +2661,7 @@
 			g_free (parent);
 		}
 
-		if (tracker_config_get_enable_xesam (config)) {
+		if (tracker_config_get_enable_xesam (private->config)) {
 			/* FIXME: Shouldn't this be the common interface? */
 			db_create_event (iface, sid, "Create");
 		}

Modified: branches/indexer-split/src/trackerd/tracker-db.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-db.h	(original)
+++ branches/indexer-split/src/trackerd/tracker-db.h	Thu Aug 21 17:33:36 2008
@@ -40,11 +40,15 @@
 
 G_BEGIN_DECLS
 
-void                tracker_db_init                              (TrackerConfig       *this_config,
-								  TrackerLanguage     *this_language,
-								  TrackerDBIndex      *this_file_index);
+void                tracker_db_init                              (TrackerConfig       *config,
+								  TrackerLanguage     *language,
+								  TrackerDBIndex      *file_index,
+								  TrackerDBIndex      *email_index);
 void                tracker_db_shutdown                          (void);
 
+GArray *            tracker_db_create_array_of_services          (const gchar         *service,
+								  gboolean             basic_services);
+
 /* Operations for TrackerDBInterface */
 TrackerDBResultSet *tracker_db_exec_proc                         (TrackerDBInterface  *iface,
 								  const gchar         *procedure,

Modified: branches/indexer-split/src/trackerd/tracker-dbus.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-dbus.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-dbus.c	Thu Aug 21 17:33:36 2008
@@ -305,14 +305,16 @@
 gboolean
 tracker_dbus_register_objects (TrackerConfig    *config,
 			       TrackerLanguage  *language,
-			       TrackerDBIndex   *index,
+			       TrackerDBIndex   *file_index,
+			       TrackerDBIndex   *email_index,
 			       TrackerProcessor *processor)
 {
 	gpointer object;
 
 	g_return_val_if_fail (TRACKER_IS_CONFIG (config), FALSE);
 	g_return_val_if_fail (TRACKER_IS_LANGUAGE (language), FALSE);
-	g_return_val_if_fail (TRACKER_IS_DB_INDEX (index), FALSE);
+	g_return_val_if_fail (TRACKER_IS_DB_INDEX (file_index), FALSE);
+	g_return_val_if_fail (TRACKER_IS_DB_INDEX (email_index), FALSE);
 
 	if (!connection || !proxy) {
 		g_critical ("DBus support must be initialized before registering objects!");
@@ -376,7 +378,7 @@
         objects = g_slist_prepend (objects, object);
 
         /* Add org.freedesktop.Tracker.Search */
-	object = tracker_search_new (config, language, index);
+	object = tracker_search_new (config, language, file_index, email_index);
 	if (!object) {
 		g_critical ("Could not create TrackerSearch object to register");
 		return FALSE;

Modified: branches/indexer-split/src/trackerd/tracker-dbus.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-dbus.h	(original)
+++ branches/indexer-split/src/trackerd/tracker-dbus.h	Thu Aug 21 17:33:36 2008
@@ -39,7 +39,8 @@
 void        tracker_dbus_shutdown          (void);
 gboolean    tracker_dbus_register_objects  (TrackerConfig    *config,
 					    TrackerLanguage  *language,
-					    TrackerDBIndex   *file,
+					    TrackerDBIndex   *file_index,
+					    TrackerDBIndex   *email_index,
 					    TrackerProcessor *processor);
 GObject    *tracker_dbus_get_object        (GType             type);
 DBusGProxy *tracker_dbus_indexer_get_proxy (void);

Modified: branches/indexer-split/src/trackerd/tracker-main.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-main.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-main.c	Thu Aug 21 17:33:36 2008
@@ -638,8 +638,9 @@
         TrackerConfig              *config;
         TrackerLanguage            *language;
         TrackerHal                 *hal;
-        TrackerDBIndex             *index;
-        TrackerDBIndex             *index_update;
+        TrackerDBIndex             *file_index;
+        TrackerDBIndex             *file_update_index;
+        TrackerDBIndex             *email_index;
 	TrackerRunningLevel         runtime_level;
 	TrackerDBManagerFlags       flags = 0;
 	TrackerDBIndexManagerFlags  index_flags = 0;
@@ -842,16 +843,18 @@
 		return EXIT_FAILURE;
 	}
 
-	index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_TYPE_INDEX);
-	index_update = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_TYPE_INDEX_UPDATE);
-
-	if (!TRACKER_IS_DB_INDEX (index) || 
-	    !TRACKER_IS_DB_INDEX (index_update)) {
-		g_critical ("Could not create indexer for all indexes (index, index-update)");
+	file_index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_FILE);
+	file_update_index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_FILE_UPDATE);
+	email_index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_EMAIL);
+
+	if (!TRACKER_IS_DB_INDEX (file_index) || 
+	    !TRACKER_IS_DB_INDEX (file_update_index) ||
+	    !TRACKER_IS_DB_INDEX (email_index)) {
+		g_critical ("Could not create indexer for all indexes (file, file-update, email)");
 		return EXIT_FAILURE;
 	}
 
-	tracker_db_init (config, language, index);
+	tracker_db_init (config, language, file_index, email_index);
 	tracker_xesam_manager_init ();
 
 	private->processor = tracker_processor_new (config, hal);
@@ -859,7 +862,8 @@
 	/* Make Tracker available for introspection */
 	if (!tracker_dbus_register_objects (config,
 					    language,
-					    index,
+					    file_index,
+					    email_index,
 					    private->processor)) {
 		return EXIT_FAILURE;
 	}

Modified: branches/indexer-split/src/trackerd/tracker-processor.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-processor.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-processor.c	Thu Aug 21 17:33:36 2008
@@ -1033,7 +1033,10 @@
 	 * module_name->index type so we don't do this for both
 	 * every time:
 	 */
-	index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_TYPE_INDEX);
+	index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_FILE);
+	tracker_db_index_set_reload (index, TRUE);
+
+	index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_EMAIL);
 	tracker_db_index_set_reload (index, TRUE);
 
 	/* Message to the console about state */
@@ -1079,7 +1082,10 @@
 	 * module_name->index type so we don't do this for both
 	 * every time:
 	 */
-	index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_TYPE_INDEX);
+	index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_FILE);
+	tracker_db_index_set_reload (index, TRUE);
+
+	index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_EMAIL);
 	tracker_db_index_set_reload (index, TRUE);
 
 	/* Message to the console about state */

Modified: branches/indexer-split/src/trackerd/tracker-query-tree.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-query-tree.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-query-tree.c	Thu Aug 21 17:33:36 2008
@@ -1,5 +1,6 @@
-/* Tracker - index and metadata database engine
- * Copyright (C) 2007-2008 Nokia
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* 
+ * Copyright (C) 2008, Nokia
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public
@@ -37,6 +38,7 @@
 #include <libtracker-common/tracker-ontology.h>
 
 #include <libtracker-db/tracker-db-index-item.h>
+#include <libtracker-db/tracker-db-index-manager.h>
 
 #include "tracker-query-tree.h"
 #include "tracker-utils.h"
@@ -69,7 +71,6 @@
 struct TrackerQueryTreePrivate {
 	gchar           *query_str;
 	TreeNode        *tree;
-	TrackerDBIndex  *index;
         TrackerConfig   *config;
         TrackerLanguage *language;
 	GArray          *services;
@@ -89,9 +90,6 @@
 enum {
 	PROP_0,
 	PROP_QUERY,
-	PROP_INDEX,
-        PROP_CONFIG,
-        PROP_LANGUAGE,
 	PROP_SERVICES
 };
 
@@ -126,27 +124,6 @@
 							      NULL,
 							      G_PARAM_READWRITE));
 	g_object_class_install_property (object_class,
-					 PROP_INDEX,
-					 g_param_spec_object ("index",
-                                                              "Index",
-                                                              "Index",
-                                                              tracker_db_index_get_type (),
-                                                              G_PARAM_READWRITE));
-	g_object_class_install_property (object_class,
-					 PROP_CONFIG,
-					 g_param_spec_object ("config",
-                                                              "Config",
-                                                              "Config",
-                                                              tracker_config_get_type (),
-                                                              G_PARAM_READWRITE));
-	g_object_class_install_property (object_class,
-					 PROP_LANGUAGE,
-					 g_param_spec_object ("language",
-                                                              "Language",
-                                                              "Language",
-                                                              tracker_language_get_type (),
-                                                              G_PARAM_READWRITE));
-	g_object_class_install_property (object_class,
 					 PROP_SERVICES,
 					 g_param_spec_pointer ("services",
 							       "Services",
@@ -224,18 +201,6 @@
 		tracker_query_tree_set_query (TRACKER_QUERY_TREE (object),
 					      g_value_get_string (value));
 		break;
-	case PROP_INDEX:
-		tracker_query_tree_set_index (TRACKER_QUERY_TREE (object),
-                                              g_value_get_object (value));
-		break;
-	case PROP_CONFIG:
-		tracker_query_tree_set_config (TRACKER_QUERY_TREE (object),
-                                               g_value_get_object (value));
-		break;
-	case PROP_LANGUAGE:
-		tracker_query_tree_set_language (TRACKER_QUERY_TREE (object),
-						 g_value_get_object (value));
-		break;
 	case PROP_SERVICES:
 		tracker_query_tree_set_services (TRACKER_QUERY_TREE (object),
 						 g_value_get_pointer (value));
@@ -259,15 +224,6 @@
 	case PROP_QUERY:
 		g_value_set_string (value, priv->query_str);
 		break;
-	case PROP_INDEX:
-		g_value_set_object (value, priv->index);
-		break;
-	case PROP_CONFIG:
-		g_value_set_object (value, priv->config);
-		break;
-	case PROP_LANGUAGE:
-		g_value_set_object (value, priv->language);
-		break;
 	case PROP_SERVICES:
 		g_value_set_pointer (value, priv->services);
 		break;
@@ -278,28 +234,41 @@
 
 TrackerQueryTree *
 tracker_query_tree_new (const gchar     *query_str,
-			TrackerDBIndex  *index,
                         TrackerConfig   *config,
                         TrackerLanguage *language,
 			GArray          *services)
 {
+        TrackerQueryTree        *object;
+        TrackerQueryTreePrivate *priv;
+
+        /* We accept one or both index and services, but not NULL for
+         * both since we require at least one of them.
+         */
 	g_return_val_if_fail (query_str != NULL, NULL);
-	g_return_val_if_fail (TRACKER_IS_DB_INDEX (index), NULL);
 	g_return_val_if_fail (TRACKER_IS_CONFIG (config), NULL);
 	g_return_val_if_fail (TRACKER_IS_LANGUAGE (language), NULL);
+        g_return_val_if_fail (services != NULL, NULL);
 
         /* NOTE: The "query" has to come AFTER the "config" and
          * "language" properties since setting the query actually
          * uses the priv->config and priv->language settings.
          * Changing this order results in warnings.
          */
-	return g_object_new (TRACKER_TYPE_QUERY_TREE,
-			     "index", index,
-                             "config", config,
-                             "language", language,
-			     "services", services,
-			     "query", query_str,
-			     NULL);
+
+	object = g_object_new (TRACKER_TYPE_QUERY_TREE, NULL);
+
+        priv = TRACKER_QUERY_TREE_GET_PRIVATE (object);
+
+        priv->config = g_object_ref (config);
+        priv->language = g_object_ref (language);
+
+        if (services) {
+                tracker_query_tree_set_services (object, services);
+        }
+
+        tracker_query_tree_set_query (object, query_str);
+
+        return object;
 }
 
 #if 0
@@ -484,114 +453,6 @@
 }
 
 void
-tracker_query_tree_set_index (TrackerQueryTree *tree,
-                              TrackerDBIndex   *index)
-{
-	TrackerQueryTreePrivate *priv;
-
-	g_return_if_fail (TRACKER_IS_QUERY_TREE (tree));
-	g_return_if_fail (TRACKER_IS_DB_INDEX (index));
-
-	priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
-
-	if (index) {
-		g_object_ref (index);
-	}
-
-	if (priv->index) {
-		g_object_unref (priv->index);
-	}
-
-	priv->index = index;
-
-	g_object_notify (G_OBJECT (tree), "index");
-}
-
-TrackerDBIndex *
-tracker_query_tree_get_index (TrackerQueryTree *tree)
-{
-	TrackerQueryTreePrivate *priv;
-
-	g_return_val_if_fail (TRACKER_IS_QUERY_TREE (tree), NULL);
-
-	priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
-
-	return priv->index;
-}
-
-void
-tracker_query_tree_set_config (TrackerQueryTree *tree,
-			       TrackerConfig    *config)
-{
-	TrackerQueryTreePrivate *priv;
-
-	g_return_if_fail (TRACKER_IS_QUERY_TREE (tree));
-	g_return_if_fail (TRACKER_IS_CONFIG (config));
-
-	priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
-
-	if (config) {
-		g_object_ref (config);
-	}
-
-	if (priv->config) {
-		g_object_unref (priv->config);
-	}
-
-	priv->config = config;
-
-	g_object_notify (G_OBJECT (tree), "config");
-}
-
-TrackerConfig *
-tracker_query_tree_get_config (TrackerQueryTree *tree)
-{
-	TrackerQueryTreePrivate *priv;
-
-	g_return_val_if_fail (TRACKER_IS_QUERY_TREE (tree), NULL);
-
-	priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
-
-	return priv->config;
-}
-
-void
-tracker_query_tree_set_language (TrackerQueryTree *tree,
-                                 TrackerLanguage  *language)
-{
-	TrackerQueryTreePrivate *priv;
-
-	g_return_if_fail (TRACKER_IS_QUERY_TREE (tree));
-	g_return_if_fail (language != NULL);
-
-	priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
-
-	if (language) {
-		g_object_ref (language);
-	}
-
-	if (priv->language) {
-		g_object_unref (priv->language);
-	}
-
-	priv->language = language;
-
-	g_object_notify (G_OBJECT (tree), "language");
-}
-
-TrackerLanguage *
-tracker_query_tree_get_language (TrackerQueryTree *tree)
-{
-	TrackerQueryTreePrivate *priv;
-
-	g_return_val_if_fail (TRACKER_IS_QUERY_TREE (tree), NULL);
-
-	priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
-
-	return priv->language;
-}
-
-void
 tracker_query_tree_set_services (TrackerQueryTree *tree,
 				 GArray           *services)
 {
@@ -642,20 +503,6 @@
 	}
 }
 
-GSList *
-tracker_query_tree_get_words (TrackerQueryTree *tree)
-{
-	TrackerQueryTreePrivate *priv;
-	GSList *list = NULL;
-
-	g_return_val_if_fail (TRACKER_IS_QUERY_TREE (tree), NULL);
-
-	priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
-	get_tree_words (priv->tree, &list);
-
-	return list;
-}
-
 static gint
 get_idf_score (TrackerDBIndexItem *details,
                gfloat              idf)
@@ -670,7 +517,8 @@
 }
 
 static gboolean
-in_array (GArray *array, gint element)
+in_array (GArray *array, 
+          gint    element)
 {
 	guint i;
 
@@ -686,46 +534,93 @@
 }
 
 static void
-search_hit_data_free (SearchHitData *search_hit)
+search_hit_data_free (gpointer data)
 {
-	g_slice_free (SearchHitData, search_hit);
+	g_slice_free (SearchHitData, data);
 }
 
-static GHashTable *
-get_search_term_hits (TrackerQueryTree *tree,
-		      const gchar      *term)
+static void
+add_search_term_hits_to_hash_table (TrackerDBIndexItem *items,
+                                    guint               item_count,
+                                    GArray             *services,
+                                    GHashTable         *result)
 {
-	TrackerQueryTreePrivate *priv;
-	TrackerDBIndexItem *details;
-	GHashTable *result;
-	guint count, i;
-
-	priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
-	result = g_hash_table_new_full (NULL, NULL, NULL,
-					(GDestroyNotify) search_hit_data_free);
-
-	details = tracker_db_index_get_word_hits (priv->index, term, &count);
-
-	if (!details)
-		return result;
+        guint i;
 
-	for (i = 0; i < count; i++) {
+	for (i = 0; i < item_count; i++) {
 		SearchHitData *data;
-		gint service;
+		gint           service;
 
-		service = tracker_db_index_item_get_service_type (&details[i]);
+		service = tracker_db_index_item_get_service_type (&items[i]);
 
-		if (in_array (priv->services, service)) {
+		if (in_array (services, service)) {
 			data = g_slice_new (SearchHitData);
 			data->service_type_id = service;
-			data->score = get_idf_score (&details[i], (float) 1 / count);
+			data->score = get_idf_score (&items[i], (float) 1 / item_count);
 
-			g_hash_table_insert (result, GINT_TO_POINTER (details[i].id), data);
+			g_hash_table_insert (result, GINT_TO_POINTER (items[i].id), data);
 		}
 	}
+}
+
+static GHashTable *
+get_search_term_hits (TrackerQueryTree *tree,
+		      const gchar      *term)
+{
+	TrackerQueryTreePrivate *priv;
+	TrackerDBIndexItem      *items;
+	guint                    item_count;
+	GHashTable              *result;
+        GHashTable              *indexes_checked;
+        guint                    i;
+
+	priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
+
+	result = g_hash_table_new_full (NULL, 
+                                        NULL,
+                                        NULL,
+					search_hit_data_free);
 
-	g_free (details);
+        if (!priv->services) {
+                return result;
+        }
 
+        /* Make sure we don't get information from the same
+         * index more than once.
+         */
+        indexes_checked = g_hash_table_new (g_direct_hash,
+                                            g_direct_equal);
+        
+        for (i = 0; i < priv->services->len; i++) {
+                TrackerDBIndex *index;
+                guint           id;
+
+                id = g_array_index (priv->services, gint, i);
+                index = tracker_db_index_manager_get_index_by_service_id (id);
+                
+                if (g_hash_table_lookup (indexes_checked, index)) {
+                        continue;
+                }
+                
+                g_hash_table_insert (indexes_checked, 
+                                     index, 
+                                     GINT_TO_POINTER (1));
+                
+                items = tracker_db_index_get_word_hits (index, term, &item_count);
+                
+                if (!items) {
+                        continue;
+                }
+                
+                add_search_term_hits_to_hash_table (items, 
+                                                    item_count, 
+                                                    priv->services, 
+                                                    result);
+                g_free (items);
+        }
+        
+        g_hash_table_unref (indexes_checked);
+        
 	return result;
 }
 
@@ -734,7 +629,7 @@
 		      gpointer value,
 		      gpointer user_data)
 {
-	SearchHitData *hit1, *hit2, *hit;
+	SearchHitData   *hit1, *hit2, *hit;
 	ComposeHitsData *data;
 
 	data = (ComposeHitsData *) user_data;
@@ -783,8 +678,10 @@
 	if (op == OP_OR) {
 		data.dest_table = g_hash_table_ref (data.other_table);
 	} else {
-		data.dest_table = g_hash_table_new_full (NULL, NULL, NULL,
-							 (GDestroyNotify) search_hit_data_free);
+		data.dest_table = g_hash_table_new_full (NULL, 
+                                                         NULL, 
+                                                         NULL,
+							 search_hit_data_free);
 	}
 
 	g_hash_table_foreach (foreach_table, (GHFunc) compose_hits_foreach, &data);
@@ -852,6 +749,20 @@
 	return (bp->score - ap->score);
 }
 
+GSList *
+tracker_query_tree_get_words (TrackerQueryTree *tree)
+{
+	TrackerQueryTreePrivate *priv;
+	GSList *list = NULL;
+
+	g_return_val_if_fail (TRACKER_IS_QUERY_TREE (tree), NULL);
+
+	priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
+	get_tree_words (priv->tree, &list);
+
+	return list;
+}
+
 GArray *
 tracker_query_tree_get_hits (TrackerQueryTree *tree,
 			     guint             offset,

Modified: branches/indexer-split/src/trackerd/tracker-query-tree.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-query-tree.h	(original)
+++ branches/indexer-split/src/trackerd/tracker-query-tree.h	Thu Aug 21 17:33:36 2008
@@ -30,8 +30,6 @@
 #include <libtracker-common/tracker-config.h>
 #include <libtracker-common/tracker-language.h>
 
-#include <libtracker-db/tracker-db-index.h>
-
 #define TRACKER_TYPE_QUERY_TREE         (tracker_query_tree_get_type())
 #define TRACKER_QUERY_TREE(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_QUERY_TREE, TrackerQueryTree))
 #define TRACKER_QUERY_TREE_CLASS(c)     (G_TYPE_CHECK_CLASS_CAST ((c),    TRACKER_TYPE_QUERY_TREE, TrackerQueryTreeClass))
@@ -58,22 +56,13 @@
 
 GType                 tracker_query_tree_get_type       (void);
 TrackerQueryTree *    tracker_query_tree_new            (const gchar      *query_str,
-                                                         TrackerDBIndex   *index,
 							 TrackerConfig    *config,
 							 TrackerLanguage  *language,
                                                          GArray           *services);
 G_CONST_RETURN gchar *tracker_query_tree_get_query      (TrackerQueryTree *tree);
 void                  tracker_query_tree_set_query      (TrackerQueryTree *tree,
                                                          const gchar      *query_str);
-TrackerDBIndex *      tracker_query_tree_get_index      (TrackerQueryTree *tree);
-void                  tracker_query_tree_set_index      (TrackerQueryTree *tree,
-							 TrackerDBIndex   *indexer);
-TrackerConfig *       tracker_query_tree_get_config     (TrackerQueryTree *tree);
-void                  tracker_query_tree_set_config     (TrackerQueryTree *tree,
-                                                         TrackerConfig    *config);
-TrackerLanguage *     tracker_query_tree_get_language   (TrackerQueryTree *tree);
-void                  tracker_query_tree_set_language   (TrackerQueryTree *tree,
-                                                         TrackerLanguage  *language);
+
 GArray *              tracker_query_tree_get_services   (TrackerQueryTree *tree);
 void                  tracker_query_tree_set_services   (TrackerQueryTree *tree,
                                                          GArray           *services);

Modified: branches/indexer-split/src/trackerd/tracker-search.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-search.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-search.c	Thu Aug 21 17:33:36 2008
@@ -49,7 +49,8 @@
 typedef struct {
 	TrackerConfig   *config;
 	TrackerLanguage *language;
-        TrackerDBIndex  *index;
+        TrackerDBIndex  *file_index;
+        TrackerDBIndex  *email_index;
 } TrackerSearchPrivate;
 
 static void tracker_search_finalize (GObject *object);
@@ -80,7 +81,8 @@
 	
 	priv = TRACKER_SEARCH_GET_PRIVATE (object);
 
-	g_object_unref (priv->index);
+	g_object_unref (priv->email_index);
+	g_object_unref (priv->file_index);
 	g_object_unref (priv->language);
 	g_object_unref (priv->config);
 
@@ -90,14 +92,16 @@
 TrackerSearch *
 tracker_search_new (TrackerConfig   *config,
 		    TrackerLanguage *language,
-		    TrackerDBIndex  *index)
+		    TrackerDBIndex  *file_index,
+		    TrackerDBIndex  *email_index)
 {
 	TrackerSearch        *object;
 	TrackerSearchPrivate *priv;
 
 	g_return_val_if_fail (TRACKER_IS_CONFIG (config), NULL);
 	g_return_val_if_fail (TRACKER_IS_LANGUAGE (language), NULL);
-	g_return_val_if_fail (TRACKER_IS_DB_INDEX (index), NULL);
+	g_return_val_if_fail (TRACKER_IS_DB_INDEX (file_index), NULL);
+	g_return_val_if_fail (TRACKER_IS_DB_INDEX (email_index), NULL);
 
 	object = g_object_new (TRACKER_TYPE_SEARCH, NULL); 
 
@@ -105,7 +109,8 @@
 
 	priv->config = g_object_ref (config);
 	priv->language = g_object_ref (language);
-	priv->index = g_object_ref (index);
+	priv->file_index = g_object_ref (file_index);
+	priv->email_index = g_object_ref (email_index);
 
 	return object;
 }
@@ -434,8 +439,6 @@
 	GError               *actual_error = NULL;
 	GArray               *array;
 	guint                 request_id;
-	gint                  services[12];
-	gint                  count = 0;
 
 	request_id = tracker_dbus_get_next_request_id ();
 
@@ -471,31 +474,8 @@
 
 	priv = TRACKER_SEARCH_GET_PRIVATE (object);
 
-	services[count++] = tracker_ontology_get_id_for_service_type (service);
-
-	if (strcmp (service, "Files") == 0) {
-		services[count++] = tracker_ontology_get_id_for_service_type ("Folders");
-		services[count++] = tracker_ontology_get_id_for_service_type ("Documents");
-		services[count++] = tracker_ontology_get_id_for_service_type ("Images");
-		services[count++] = tracker_ontology_get_id_for_service_type ("Videos");
-		services[count++] = tracker_ontology_get_id_for_service_type ("Music");
-		services[count++] = tracker_ontology_get_id_for_service_type ("Text");
-		services[count++] = tracker_ontology_get_id_for_service_type ("Development");
-		services[count++] = tracker_ontology_get_id_for_service_type ("Other");
-	} else if (strcmp (service, "Emails") == 0) {
-		services[count++] = tracker_ontology_get_id_for_service_type ("EvolutionEmails");
-		services[count++] = tracker_ontology_get_id_for_service_type ("KMailEmails");
-		services[count++] = tracker_ontology_get_id_for_service_type ("ThunderbirdEmails");
- 	} else if (strcmp (service, "Conversations") == 0) {
-		services[count++] = tracker_ontology_get_id_for_service_type ("GaimConversations");
-	}
-
-	services[count] = 0;
-
-	array = g_array_new (TRUE, TRUE, sizeof (gint));
-	g_array_append_vals (array, services, G_N_ELEMENTS (services));
+	array = tracker_db_create_array_of_services (service, FALSE);
 	tree = tracker_query_tree_new (search_text, 
-				       priv->index, 
 				       priv->config,
 				       priv->language,
 				       array);
@@ -521,6 +501,7 @@
 	GArray                *hit_counts;
 	guint                  request_id;
 	guint                  i;
+	GArray                *array;
 	GPtrArray             *values = NULL;
 
 	request_id = tracker_dbus_get_next_request_id ();
@@ -544,11 +525,12 @@
 
 	priv = TRACKER_SEARCH_GET_PRIVATE (object);
 
+	array = tracker_db_create_array_of_services (NULL, FALSE);
 	tree = tracker_query_tree_new (search_text, 
-				       priv->index, 
 				       priv->config,
 				       priv->language,
-				       NULL);
+				       array);
+	g_array_free (array, TRUE);
 
 	hit_counts = tracker_query_tree_get_hit_counts (tree);
 
@@ -1237,7 +1219,16 @@
 
 	priv = TRACKER_SEARCH_GET_PRIVATE (object);
 
-	value = tracker_db_index_get_suggestion (priv->index, search_text, max_dist);
+	/* First we try the file index */
+	value = tracker_db_index_get_suggestion (priv->file_index, 
+						 search_text, 
+						 max_dist);
+	if (!value) {
+		/* Second we try the email index */
+		value = tracker_db_index_get_suggestion (priv->email_index, 
+							 search_text, 
+							 max_dist);
+	}
 
 	if (!value) {
 		g_set_error (&actual_error,

Modified: branches/indexer-split/src/trackerd/tracker-search.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-search.h	(original)
+++ branches/indexer-split/src/trackerd/tracker-search.h	Thu Aug 21 17:33:36 2008
@@ -55,7 +55,8 @@
 GType          tracker_search_get_type          (void);
 TrackerSearch *tracker_search_new               (TrackerConfig          *config,
 						 TrackerLanguage        *language,
-						 TrackerDBIndex         *index);
+						 TrackerDBIndex         *file_index,
+						 TrackerDBIndex         *email_index);
 void           tracker_search_get_hit_count     (TrackerSearch          *object,
 						 const gchar            *service,
 						 const gchar            *search_text,

Modified: branches/indexer-split/tests/libtracker-common/tracker-ontology-test.c
==============================================================================
--- branches/indexer-split/tests/libtracker-common/tracker-ontology-test.c	(original)
+++ branches/indexer-split/tests/libtracker-common/tracker-ontology-test.c	Thu Aug 21 17:33:36 2008
@@ -277,9 +277,9 @@
 {
 	TrackerDBType result_db;
 
-	result_db = tracker_ontology_get_db_for_service_type ("Test service");
+	result_db = tracker_ontology_get_db_by_service_type ("Test service");
 	g_assert (result_db == TRACKER_DB_TYPE_FILES); // ????? HARDCODED IN tracker-ontology!!!!!
-	result_db = tracker_ontology_get_db_for_service_type ("trash");
+	result_db = tracker_ontology_get_db_by_service_type ("trash");
 	g_assert (result_db == TRACKER_DB_TYPE_FILES);
 }
 



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