 +
 +  if (sexp_error == -1)
 +  {
-+    g_warning ("Failed to parse query %s, %s", query, e_sexp_error (sexp));
++    g_warning (G_STRLOC ": Failed to parse query %s, %s", query, e_sexp_error (sexp));
 +    e_sexp_unref (sexp);
 +    return FALSE;
 +  }

+  /* evaluate ... */
+  sexp_result = e_sexp_eval(sexp);
+
+  if (sexp_result)
+  {
+    if (sexp_result->type == ESEXP_RES_BOOL)
+    {
+      /* return the value of whether we can actually use the index */
+      res = sexp_result->value.bool;
+    } else {
+      g_warning ("Unexpected result type");
+    }
+
+    e_sexp_result_free (sexp, sexp_result);
+  }
+
+  e_sexp_unref (sexp);
+  return res;
+}
+
+/* functions used for testing whether we can use the index */

 };
 
 G_LOCK_DEFINE_STATIC (global_env);
@@ -246,6 +249,7 @@
 	status = do_create (bf, vcard, contact);
 	if (status == GNOME_Evolution_Addressbook_Success) {
 		e_book_backend_summary_add_contact (bf->priv->summary, *contact);
+		e_book_backend_file_index_add_contact (bf->priv->index, *contact);
 	}
 	return status;
 }
@@ -293,6 +297,7 @@
 	for (l = removed_cards; l; l = l->next) {
 		char *id = l->data;
 		e_book_backend_summary_remove_contact (bf->priv->summary, id);
+		e_book_backend_file_index_remove_contact (bf->priv->index, id);
 	}
 
 	return rv;
@@ -345,6 +350,7 @@
 	g_free (vcard_with_rev);
 	
 	if (db_error == 0) {
+		e_book_backend_file_index_modify_contact (bf->priv->index, *contact);
 		return GNOME_Evolution_Addressbook_Success;
 	} else {
 		g_warning (G_STRLOC ": db->put failed with %s", db_strerror (db_error));
@@ -642,11 +648,44 @@
 	d(printf ("signalling parent thread\n"));
 	e_flag_set (closure->running);
 
-	if (e_book_backend_summary_is_summary_query (bf->priv->summary, query)) {
+
+	g_debug (G_STRLOC ": Query is %s", query);
+	if (e_book_backend_file_index_is_usable (bf->priv->index, query))
+	{
+		GPtrArray *ids = NULL;
+		int i;
+
+		ids = e_book_backend_file_index_query (bf->priv->index, query);
+
+		for (i = 0; i < ids->len; i ++) {
+			char *id = g_ptr_array_index (ids, i);
+
+			if (!e_flag_is_set (closure->running))
+				break;
+
+			string_to_dbt (id, &id_dbt);
+			memset (&vcard_dbt, 0, sizeof (vcard_dbt));
+			vcard_dbt.flags = DB_DBT_MALLOC;
+
+			db_error = db->get (db, NULL, &id_dbt, &vcard_dbt, 0);
+
+			if (db_error == 0) {
+				e_data_book_view_notify_update_prefiltered_vcard (book_view, id, vcard_dbt.data);
+			}
+			else {
+				g_warning (G_STRLOC ": db->get failed with %s", db_strerror (db_error));
+			}
+		}
+
+		e_book_backend_file_index_finish_query (bf->priv->index);
+		g_ptr_array_free (ids, TRUE);
+	} else if (e_book_backend_summary_is_summary_query (bf->priv->summary, query)) {
 		/* do a summary query */
 		GPtrArray *ids = e_book_backend_summary_search (bf->priv->summary, e_data_book_view_get_card_query (book_view));
 		int i;
 
+		g_debug (G_STRLOC ": Using summmary for %s", query);
+
 		for (i = 0; i < ids->len; i ++) {
 			char *id = g_ptr_array_index (ids, i);
 
@@ -668,8 +707,7 @@
 		}
 
 		g_ptr_array_free (ids, TRUE);
-	}
-	else {
+	} else {
 		/* iterate over the db and do the query there */
 		DBC    *dbc;
 
@@ -709,13 +747,14 @@
 				   bf->priv->filename);
 			abort ();
 		}
-
-
 	}
 
 	if (e_flag_is_set (closure->running))
+	{
 		e_data_book_view_notify_complete (book_view, GNOME_Evolution_Addressbook_Success);
 
+	}
+
 	/* unref the */
 	g_object_unref (book_view);
 
@@ -1143,6 +1182,8 @@
 	time_t db_mtime;
 	struct stat sb;
 	gchar *uri;
+	gchar *index_filename;
+
 
 	uri = e_source_get_uri (source);
 
@@ -1317,12 +1358,22 @@
 	g_free (bf->priv->summary_filename);
 	bf->priv->summary_filename = g_strconcat (bf->priv->filename, ".summary", NULL);
 	bf->priv->summary = e_book_backend_summary_new (bf->priv->summary_filename, SUMMARY_FLUSH_TIMEOUT);
