tracker r1539 - in branches/indexer-split: . data data/services src/trackerd



Author: pvanhoof
Date: Fri May 30 09:32:30 2008
New Revision: 1539
URL: http://svn.gnome.org/viewvc/tracker?rev=1539&view=rev

Log:
2008-05-30  Philip Van Hoof  <pvanhoof gnome org>

	* Merged indexer-split with xesam-support
	svn merge -r 1495:1538 ../xesam-support



Added:
   branches/indexer-split/src/trackerd/tracker-metadata.c
      - copied unchanged from r1538, /branches/xesam-support/src/trackerd/tracker-metadata.c
   branches/indexer-split/src/trackerd/tracker-metadata.h
      - copied unchanged from r1538, /branches/xesam-support/src/trackerd/tracker-metadata.h
   branches/indexer-split/src/trackerd/tracker-xesam.c
      - copied unchanged from r1538, /branches/xesam-support/src/trackerd/tracker-xesam.c
   branches/indexer-split/src/trackerd/tracker-xesam.h
      - copied unchanged from r1538, /branches/xesam-support/src/trackerd/tracker-xesam.h
Modified:
   branches/indexer-split/ChangeLog
   branches/indexer-split/data/services/xesam-metadata.mmapping
   branches/indexer-split/data/sqlite-stored-procs.sql
   branches/indexer-split/src/trackerd/tracker-db-sqlite.c
   branches/indexer-split/src/trackerd/tracker-db-sqlite.h
   branches/indexer-split/src/trackerd/tracker-rdf-query.c
   branches/indexer-split/src/trackerd/tracker-xesam-live-search.c
   branches/indexer-split/src/trackerd/tracker-xesam-live-search.h
   branches/indexer-split/src/trackerd/tracker-xesam-query.c
   branches/indexer-split/src/trackerd/tracker-xesam-query.h
   branches/indexer-split/src/trackerd/tracker-xesam-session.c

Modified: branches/indexer-split/data/services/xesam-metadata.mmapping
==============================================================================
--- branches/indexer-split/data/services/xesam-metadata.mmapping	(original)
+++ branches/indexer-split/data/services/xesam-metadata.mmapping	Fri May 30 09:32:30 2008
@@ -77,7 +77,7 @@
 
 
 [xesam:author]
-MetaName=
+MetaName=Email:Sender
 
 
 [xesam:autoRating]
@@ -109,7 +109,7 @@
 
 
 [xesam:cc]
-MetaName=
+MetaName=Email:CC
 
 
 [xesam:ccdWidth]
@@ -625,7 +625,7 @@
 
 
 [xesam:primaryRecipient]
-MetaName=
+MetaName=Email:Recipient
 
 
 [xesam:programmingLanguage]
@@ -637,7 +637,7 @@
 
 
 [xesam:recipient]
-MetaName=
+MetaName=Email:Recipient
 
 
 [xesam:related]
@@ -685,7 +685,7 @@
 
 
 [xesam:secondaryRecipient]
-MetaName=
+MetaName=Email:Recipient
 
 
 [xesam:seenAttachedAs]
@@ -741,7 +741,7 @@
 
 
 [xesam:to]
-MetaName=
+MetaName=Email:Recipient
 
 
 [xesam:totalSpace]

Modified: branches/indexer-split/data/sqlite-stored-procs.sql
==============================================================================
--- branches/indexer-split/data/sqlite-stored-procs.sql	(original)
+++ branches/indexer-split/data/sqlite-stored-procs.sql	Fri May 30 09:32:30 2008
@@ -29,7 +29,10 @@
 GetEvents SELECT ID, ServiceID, EventType FROM Events WHERE BeingHandled = 1;
 SetEventsBeingHandled UPDATE Events SET BeingHandled = 1;
 
+GetLiveSearchAllIDs SELECT X.ServiceID FROM LiveSearches AS X WHERE X.SearchID = ?
 GetLiveSearchDeletedIDs SELECT E.ServiceID FROM Events as E, LiveSearches as X WHERE E.ServiceID = X.ServiceID AND X.SearchID = ? AND E.EventType IS 'Delete';
+DeleteLiveSearchDeletedIDs DELETE FROM LiveSearches AS Y WHERE Y.ServiceID IN SELECT ServiceID FROM Events as E, LiveSearches as X WHERE E.ServiceID = X.ServiceID AND X.SearchID = ? AND E.EventType IS 'Delete'
+
 GetLiveSearchHitCount SELECT count(*) FROM LiveSearches WHERE SearchID = ?;
 LiveSearchStopSearch DELETE FROM LiveSearches as X WHERE E.SearchID = ?
 

Modified: branches/indexer-split/src/trackerd/tracker-db-sqlite.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-db-sqlite.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-db-sqlite.c	Fri May 30 09:32:30 2008
@@ -3304,7 +3304,15 @@
 	 * AND X.SearchID = ? 
 	 * AND E.EventType IS 'Delete' */
 
-	return tracker_db_exec_proc (db_con->db, "GetLiveSearchDeletedIDs", search_id, NULL);
+	/* DELETE FROM LiveSearches AS Y WHERE Y.ServiceID IN
+	 * SELECT ServiceID FROM Events as E, LiveSearches as X 
+	 * WHERE E.ServiceID = X.ServiceID 
+	 * AND X.SearchID = ? 
+	 * AND E.EventType IS 'Delete' */
+
+	TrackerDBResultSet *result_set = tracker_db_exec_proc (db_con->db, "GetLiveSearchDeletedIDs", search_id, NULL);
+	tracker_exec_proc_no_reply (db_con->db, "DeleteLiveSearchDeletedIDs", search_id, NULL);
+	return result_set;
 }
 
 void
@@ -3319,58 +3327,128 @@
 
 
 void
-tracker_db_start_live_search (DBConnection *db_con, const gchar *from_query, const gchar *where_query, const gchar *search_id)
+tracker_db_start_live_search (DBConnection *db_con, const gchar *from_query, const gchar *join_query, const gchar *where_query, const gchar *search_id)
 {
 	/* INSERT
 	 * INTO LiveSearches
 	 * SELECT ID, SEARCH_ID FROM_QUERY WHERE_QUERY */
 
-	g_debug ("INSERT INTO LiveSearches SELECT S.ID, '%s' %s %s",
-			search_id, from_query, where_query);
+	g_debug ("INSERT INTO LiveSearches SELECT S.ID, '%s' %s %s %s",
+		 search_id, from_query, join_query, where_query);
 
 	tracker_db_exec_no_reply (db_con->db,
-		"INSERT INTO LiveSearches SELECT S.ID, '%s' %s %s",
-			search_id, from_query, where_query);
+				  "INSERT INTO LiveSearches SELECT S.ID, '%s' %s %s %s",
+				  search_id, from_query, join_query, where_query);
 
 }
 
 TrackerDBResultSet* 
-tracker_db_get_live_search_new_ids (DBConnection *db_con, const gchar *search_id, const gchar *columns, const gchar *from_query, const gchar *where_query)
+tracker_db_get_live_search_new_ids (DBConnection *db_con, const gchar *search_id, const gchar *from_query, const gchar *query_joins, const gchar *where_query)
 {
+	TrackerDBResultSet *result_set;
+	
 	// todo: this is a query for ottela to review
 
 	/* Contract, in @result:
 	 * ServiceID is #1
 	 * EventType is #2 */
 
+	g_debug("tracker_db_get_live_search_new_ids");
+
 	/**
-	 * SELECT E.ServiceID, E.EventType, COLUMNS
-	 * FROM_QUERY XesamLiveSearches as X, Events as E
-	 * WHERE_QUERY"
+	 * SELECT E.ServiceID, E.EventType
+	 * FROM_QUERY, LiveSearches as X, Events as E
+	 * QUERY_JOINS
+	 * WHERE_QUERY
 	 * AND X.ServiceID = E.ServiceID
-	 * AND X.SearchID = SEARCH_ID
-	 * AND (X.EventType IS 'Create' 
-	 *      OR X.EventType IS 'Update')
+	 * AND X.SearchID = 'SEARCH_ID'
+	 * AND E.EventType = 'Update'
+	 * UNION
+	 * SELECT E.ServiceID, E.EventType
+	 * FROM_QUERY, Events as E
+	 * QUERY_JOINS
+	 * WHERE_QUERY
+	 * AND E.ServiceID = S.ID
+	 * AND E.EventType = 'Create'
 	 **/
 
-	g_debug("tracker_db_get_live_search_new_ids");
+	/**
+	 * INSERT INTO LiveSearches 
+	 * SELECT E.ServiceID, 'SEARCH_ID' 
+	 * FROM_QUERY, Events as E
+	 * QUERY_JOINS
+	 * WHERE_QUERY
+	 * AND E.ServiceID = S.ID
+	 * AND E.EventType = 'Create'
+	 **/
+
+	result_set = tracker_db_exec (db_con->db,
+/*           */ "SELECT E.ServiceID, E.EventType "
+/* FROM   A1 */ "%s%s LiveSearches as X, Events as E "
+/* JOINS  A2 */ "%s"
+/* WHERE  A3 */ "%s"
+/*           */ "%sX.ServiceID = E.ServiceID "
+/*        A4 */ "AND X.SearchID = '%s' "
+/*           */ "AND E.EventType = 'Update' "
+
+/*           */ "UNION "
+
+/*           */ "SELECT E.ServiceID, E.EventType "
+/* FROM   B1 */ "%s%s Events as E "
+/* JOINS  B2 */ "%s"
+/* WHERE  B3 */ "%s"
+/*           */ "%sE.ServiceID = S.ID "
+/*           */ "AND E.EventType = 'Create' ",
+
+/*        A1 */ from_query?from_query:"FROM",
+/*        A1 */ from_query?",":"",
+/*        A2 */ query_joins,
+/*        A3 */ where_query?where_query:"WHERE",
+/*        A3 */ where_query?"AND ":"",
+/*        A4 */ search_id,
+/*        B1 */ from_query?from_query:"FROM",
+/*        B1 */ from_query?",":"",
+/*        B2 */ query_joins,
+/*        B3 */ where_query?where_query:"WHERE",
+/*        B3 */ where_query?"AND ":"");
+
+
+	tracker_db_exec_no_reply (db_con->db,
+/*           */ "INSERT INTO LiveSearches "
+/*        B0 */ "SELECT E.ServiceID, '%s' "
+/* FROM   B1 */ "%s%s Events as E "
+/* JOINS  B2 */ "%s"
+/* WHERE  B3 */ "%s"
+/*           */ "%sE.ServiceID = S.ID"
+/*           */ "AND E.EventType = 'Create' ",
+
+/*        B0 */ search_id,
+/*        B1 */ from_query?from_query:"FROM",
+/*        B1 */ from_query?",":"",
+/*        B2 */ query_joins,
+/*        B3 */ where_query?where_query:"WHERE",
+/*        B3 */ where_query?"AND ":"");
+
+	return result_set;
+}
+
+
+TrackerDBResultSet* 
+tracker_db_get_live_search_all_ids (DBConnection *db_con, const gchar *search_id)
+{
+	/* Contract, in @result:
+	 * ServiceID is #1 */
+
+	/**
+	 * SELECT X.ServiceID
+	 * FROM LiveSearches as X
+	 * WHERE X.SearchID = SEARCH_ID
+	 **/
+
+	g_debug("tracker_db_get_live_search_all_ids");
+
+	return tracker_db_exec_proc (db_con->db, "GetLiveSearchAllIDs", search_id, NULL);
 
-	return tracker_db_exec (db_con->db,
-	/* COLUMNS */      "SELECT E.ServiceID, E.EventType%s%s "
-	/* FROM_QUERY */   "%s%s LiveSearches as X, Events as E "
-	/* WHERE_QUERY */  "%s"
-	/* AND or space */ "%sX.ServiceID = E.ServiceID "
-			   "AND X.SearchID = '%s' " /* search_id arg */
-			   "AND (X.EventType IS 'Create' "
-			   "OR X.EventType IS 'Update') ",
-
-			   columns?", ":"", 
-			   columns?columns:"", 
-			   from_query?from_query:"FROM",
-			   from_query?",":"",
-			   where_query?where_query:"WHERE",
-			   where_query?"AND":" ", 
-			   search_id);
 }
 
 TrackerDBResultSet *

Modified: branches/indexer-split/src/trackerd/tracker-db-sqlite.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-db-sqlite.h	(original)
+++ branches/indexer-split/src/trackerd/tracker-db-sqlite.h	Fri May 30 09:32:30 2008
@@ -327,9 +327,11 @@
                                                                 const gchar *search_id);
 TrackerDBResultSet *tracker_db_get_live_search_new_ids         (DBConnection *db_con, 
                                                                 const gchar *search_id,
-                                                                const gchar *columns, 
-                                                                const gchar *tables, 
-                                                                const gchar *query);
+                                                                const gchar *from_query, 
+                                                                const gchar *query_joins, 
+                                                                const gchar *where_query);
+TrackerDBResultSet *tracker_db_get_live_search_all_ids         (DBConnection *db_con, 
+                                                                const gchar *search_id);
 TrackerDBResultSet *tracker_db_get_live_search_hit_count       (DBConnection *db_con, 
                                                                 const gchar *search_id);
 
@@ -345,7 +347,8 @@
 void                tracker_db_stop_live_search                (DBConnection *db_con, 
                                                                 const gchar *search_id);
 void                tracker_db_start_live_search               (DBConnection *db_con, 
-                                                                const gchar *from_query, 
+                                                                const gchar *from_query,
+								const gchar *join_query,
                                                                 const gchar *where_query,
                                                                 const gchar *search_id);
 TrackerDBResultSet *tracker_db_get_live_search_get_hit_data    (DBConnection *db_con, 

Modified: branches/indexer-split/src/trackerd/tracker-rdf-query.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-rdf-query.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-rdf-query.c	Fri May 30 09:32:30 2008
@@ -697,6 +697,8 @@
 		g_free (avalue);
 		g_free (data->current_field);
 		g_free (data->current_value);
+		data->current_field = NULL;
+		data->current_value = NULL;
 		return FALSE;
 	}
 

Modified: branches/indexer-split/src/trackerd/tracker-xesam-live-search.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-xesam-live-search.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-xesam-live-search.c	Fri May 30 09:32:30 2008
@@ -37,6 +37,7 @@
 	gchar               *query;
 	gchar               *from_sql;
 	gchar               *where_sql;
+	gchar               *join_sql;
 };
 
 enum {
@@ -61,6 +62,7 @@
 	g_free (priv->query);
 
 	g_free (priv->from_sql);
+	g_free (priv->join_sql);
 	g_free (priv->where_sql);
 }
 
@@ -157,6 +159,7 @@
 	priv->closed = FALSE;
 	priv->query = NULL;
 	priv->from_sql = g_strdup ("");
+	priv->join_sql = g_strdup ("");
 	priv->where_sql = g_strdup ("");
 
 }
@@ -261,74 +264,21 @@
 			       tracker_xesam_live_search_get_id (self)); 
 }
 
-/**
- * tracker_xesam_live_search_match_with_events:
- * @self: A #TrackerXesamLiveSearch
- * @added: (caller-owns) (out): added items
- * @removed: (caller-owns) (out): removed items
- * @modified: (caller-owns) (out): modified items
- *
- * Find all items that match with the current events for @self.
- **/
-void
-tracker_xesam_live_search_match_with_events (TrackerXesamLiveSearch  *self, 
-					     GArray                 **added, 
-					     GArray                 **removed, 
-					     GArray                 **modified)
+
+
+/* Created and Modified items */
+static void
+get_hits_added_modified (TrackerXesamLiveSearch *self, DBConnection *db_con, GArray **added, GArray **modified) 
 {
-	GObject            *xesam;
-	DBConnection       *db_con = NULL;
-	TrackerDBResultSet *result_set;
 	gboolean            ls_valid = TRUE;
 	GArray             *m_added = NULL;
-	GArray             *m_removed = NULL;
 	GArray             *m_modified = NULL;
-
-	g_return_if_fail (TRACKER_IS_XESAM_LIVE_SEARCH (self));
-	g_return_if_fail (added != NULL);
-	g_return_if_fail (removed != NULL);
-	g_return_if_fail (modified != NULL);
-
-	xesam = tracker_dbus_get_object (TRACKER_TYPE_XESAM);
-
-	g_object_get (xesam, "db-connection", &db_con, NULL);
-
-	/* Deleted items */
-
-	result_set = tracker_db_get_live_search_deleted_ids (db_con, 
-							     tracker_xesam_live_search_get_id (self));
-
-	if (!result_set)
-		goto part_two;
-
-	while (ls_valid) {
-		GValue ls_value = { 0, };
-		gint   ls_i_value;
-
-		_tracker_db_result_set_get_value (result_set, 0, &ls_value);
-		ls_i_value = g_value_get_int (&ls_value);
-
-		if (m_removed == NULL)
-			m_removed = g_array_new (FALSE, TRUE, sizeof (guint32));
-		g_array_append_val (m_removed, ls_i_value);
-
-		g_value_unset (&ls_value);
-
-		ls_valid = tracker_db_result_set_iter_next (result_set);
-	}
-
-	g_object_unref (result_set);
-
-part_two:
-
-	/* Created and Modified items */
-
-	ls_valid = TRUE;
+	TrackerDBResultSet *result_set;
 
 	result_set = tracker_db_get_live_search_new_ids (db_con, 
 		tracker_xesam_live_search_get_id (self),
-		NULL, /* Columns */
 		tracker_xesam_live_search_get_from_query (self),
+		tracker_xesam_live_search_get_join_query (self),
 		tracker_xesam_live_search_get_where_query (self)); /* Query */
 
 	if (!result_set)
@@ -360,13 +310,11 @@
 						break;
 					}
 			}
-
 			if (!noadd)
 				g_array_append_val (m_modified, ls_i_value);
 		} else {
 			if (m_added == NULL)
 				m_added = g_array_new (FALSE, TRUE, sizeof (guint32));
-
 			g_array_append_val (m_added, ls_i_value);
 		}
 
@@ -379,6 +327,101 @@
 	g_object_unref (result_set);
 
 	*added = m_added;
+	*modified = m_modified;
+}
+
+
+
+/* Created and Modified items */
+static void
+get_all_hits (TrackerXesamLiveSearch *self, DBConnection *db_con, GArray **hits) 
+{
+	gboolean            ls_valid = TRUE;
+	GArray             *m_hits = NULL;
+	TrackerDBResultSet *result_set;
+
+	result_set = tracker_db_get_live_search_all_ids (db_con, 
+		tracker_xesam_live_search_get_id (self));
+
+	if (!result_set)
+		return;
+
+	while (ls_valid) {
+		GValue ls_value = { 0, };
+		gint ls_i_value;
+
+		_tracker_db_result_set_get_value (result_set, 0, &ls_value);
+
+		ls_i_value = g_value_get_int (&ls_value);
+
+		if (m_hits == NULL)
+			m_hits = g_array_new (FALSE, TRUE, sizeof (guint32));
+		g_array_append_val (m_hits, ls_i_value);
+
+		g_value_unset (&ls_value);
+
+		ls_valid = tracker_db_result_set_iter_next (result_set);
+	}
+
+	g_object_unref (result_set);
+
+	*hits = m_hits;
+}
+
+
+/**
+ * tracker_xesam_live_search_match_with_events:
+ * @self: A #TrackerXesamLiveSearch
+ * @added: (caller-owns) (out): added items
+ * @removed: (caller-owns) (out): removed items
+ * @modified: (caller-owns) (out): modified items
+ *
+ * Find all items that match with the current events for @self.
+ **/
+void
+tracker_xesam_live_search_match_with_events (TrackerXesamLiveSearch *self, GArray **added, GArray **removed, GArray **modified)
+{
+	DBConnection *db_con = NULL;
+	TrackerDBResultSet *result_set;
+	gboolean ls_valid = TRUE;
+	GArray *m_added = NULL, *m_removed = NULL, *m_modified = NULL;
+
+	GObject *xesam = tracker_dbus_get_object (TRACKER_TYPE_XESAM);
+
+	g_object_get (xesam, "db-connection", &db_con, NULL);
+
+	/* Deleted items */
+
+	result_set = tracker_db_get_live_search_deleted_ids (db_con, 
+		tracker_xesam_live_search_get_id (self));
+
+	if (!result_set)
+		goto part_two;
+
+	while (ls_valid) {
+		GValue ls_value = { 0, };
+		gint ls_i_value;
+
+		_tracker_db_result_set_get_value (result_set, 0, &ls_value);
+		ls_i_value = g_value_get_int (&ls_value);
+
+		if (m_removed == NULL)
+			m_removed = g_array_new (FALSE, TRUE, sizeof (guint32));
+		g_array_append_val (m_removed, ls_i_value);
+
+		g_value_unset (&ls_value);
+
+		ls_valid = tracker_db_result_set_iter_next (result_set);
+	}
+
+	g_object_unref (result_set);
+
+part_two:
+
+	/* Created and Modified items */
+	get_hits_added_modified (self, db_con, &m_added, &m_modified);
+
+	*added = m_added;
 	*removed = m_removed;
 	*modified = m_modified;
 
@@ -768,31 +811,35 @@
 tracker_xesam_live_search_activate (TrackerXesamLiveSearch  *self, 
 				    GError                 **error)
 {
-	TrackerXesamLiveSearchPriv *priv;
-
-	g_return_if_fail (TRACKER_IS_XESAM_LIVE_SEARCH (self));
-
-	priv = self->priv;
+	TrackerXesamLiveSearchPriv *priv = self->priv;
 
-	if (priv->closed) {
-		g_set_error (error, 
-			     TRACKER_XESAM_ERROR_DOMAIN, 
-			     TRACKER_XESAM_ERROR_SEARCH_CLOSED,
-			     "Search is closed");
-	} else {
+	if (priv->closed)
+		g_set_error (error, TRACKER_XESAM_ERROR_DOMAIN, 
+				TRACKER_XESAM_ERROR_SEARCH_CLOSED,
+				"Search is closed");
+	else {
 		DBConnection *db_con = NULL;
-		GObject      *xesam;
-
-		xesam = tracker_dbus_get_object (TRACKER_TYPE_XESAM);
+		GObject      *xesam = tracker_dbus_get_object (TRACKER_TYPE_XESAM);
+		GArray       *hits = NULL;
+		
 		g_object_get (xesam, "db-connection", &db_con, NULL);
 
-		g_debug ("The from query for activate: %s",
-			 tracker_xesam_live_search_get_from_query (self)); 
-
 		tracker_db_start_live_search (db_con, 
-					      tracker_xesam_live_search_get_from_query (self),
-					      tracker_xesam_live_search_get_where_query (self),
-					      tracker_xesam_live_search_get_id (self));
+			tracker_xesam_live_search_get_from_query (self),
+			tracker_xesam_live_search_get_join_query (self),
+			tracker_xesam_live_search_get_where_query (self),
+			tracker_xesam_live_search_get_id (self));
+
+		get_all_hits (self, db_con, &hits);
+
+		if (hits && hits->len > 0) {
+			g_debug ("Emitting HitsAdded");
+			tracker_xesam_live_search_emit_hits_added (self, hits->len);
+		}
+
+		if (hits) {
+			g_array_free (hits, TRUE);
+		}
 	}
 
 	priv->active = TRUE;
@@ -883,7 +930,7 @@
 	GObject                    *xesam;
 	DBConnection               *db_con = NULL;
 	GError                     *parse_error = NULL;
-	gchar                      *orig_from, *orig_where;
+	gchar                      *orig_from, *orig_join, *orig_where;
 
 	g_return_val_if_fail (TRACKER_IS_XESAM_LIVE_SEARCH (self), FALSE);
 
@@ -893,13 +940,16 @@
 	g_object_get (xesam, "db-connection", &db_con, NULL);
 
 	orig_from = priv->from_sql;
+	orig_join = priv->join_sql;
 	orig_where = priv->where_sql;
 
 	priv->from_sql = NULL;
+	priv->join_sql = NULL;
 	priv->where_sql = NULL;
 
 	tracker_xesam_query_to_sql (db_con, priv->query, 
-				    &priv->from_sql, 
+				    &priv->from_sql,
+				    &priv->join_sql,
 				    &priv->where_sql, 
 				    &parse_error);
 
@@ -914,14 +964,17 @@
 		g_error_free (parse_error);
 
 		g_free (priv->from_sql);
+		g_free (priv->join_sql);
 		g_free (priv->where_sql);
 
 		priv->from_sql = orig_from;
+		priv->join_sql = orig_join;
 		priv->where_sql = orig_where;
 
 		return FALSE;
 	} else {
 		g_free (orig_from);
+		g_free (orig_join);
 		g_free (orig_where);
 	}
 
@@ -952,6 +1005,21 @@
 }
 
 /**
+ * tracker_xesam_live_search_get_join_query:
+ * @self: a #TrackerXesamLiveSearch
+ *
+ * Gets the parsed JOIN SQL string for the query
+ *
+ * @returns: a read-only string with the JOIN query
+ **/
+const gchar* 
+tracker_xesam_live_search_get_join_query (TrackerXesamLiveSearch *self)
+{
+	TrackerXesamLiveSearchPriv *priv = self->priv;
+	return (const gchar *) priv->join_sql;
+}
+
+/**
  * tracker_xesam_live_search_get_where_query:
  * @self: a #TrackerXesamLiveSearch
  *

Modified: branches/indexer-split/src/trackerd/tracker-xesam-live-search.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-xesam-live-search.h	(original)
+++ branches/indexer-split/src/trackerd/tracker-xesam-live-search.h	Fri May 30 09:32:30 2008
@@ -55,6 +55,7 @@
 const gchar* tracker_xesam_live_search_get_id             (TrackerXesamLiveSearch  *self);
 const gchar* tracker_xesam_live_search_get_where_query    (TrackerXesamLiveSearch  *self);
 const gchar* tracker_xesam_live_search_get_from_query     (TrackerXesamLiveSearch  *self);
+const gchar* tracker_xesam_live_search_get_join_query     (TrackerXesamLiveSearch  *self);
 const gchar* tracker_xesam_live_search_get_xml_query      (TrackerXesamLiveSearch  *self);
 void         tracker_xesam_live_search_set_xml_query      (TrackerXesamLiveSearch  *self, 
 							   const gchar             *xml_query);

Modified: branches/indexer-split/src/trackerd/tracker-xesam-query.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-xesam-query.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-xesam-query.c	Fri May 30 09:32:30 2008
@@ -155,6 +155,7 @@
 	char			*current_value;
 	DBConnection	        *db_con;
 	GString			*sql_from;
+	GString                 *sql_join;
 	GString			*sql_where;
 	char			*service;
 } ParserData;
@@ -825,6 +826,8 @@
 		g_free (avalue);
 		g_free (data->current_field);
 		g_free (data->current_value);
+		data->current_field = NULL;
+		data->current_value = NULL;
 		return FALSE;
 	}
 
@@ -840,7 +843,7 @@
 		str = g_string_new ("");
 	
 		if (i>1) {
-			g_string_append (str, " OR ");	
+			g_string_append (str, " OR ");
 		}
 		
 		if (tracker_field_data_get_data_type (field_data->data) == TRACKER_FIELD_TYPE_DATE) {
@@ -864,7 +867,7 @@
 			} else {
 				/* TODO Add error message */
 				return FALSE; 
-			}				         
+			}
 		} else {
 			value = g_strdup (avalue);
 		}
@@ -981,7 +984,7 @@
 					g_string_append_printf (str, ",'%s'", *p);
 				}
 
-				g_string_append_printf (str, ") ) " ); 					
+				g_string_append_printf (str, ") ) " ); 
 			}
 			break;
 
@@ -1201,7 +1204,7 @@
 
 
 void
-tracker_xesam_query_to_sql (DBConnection *db_con, const char *query, gchar **from, gchar **where, GError **error)
+tracker_xesam_query_to_sql (DBConnection *db_con, const char *query, gchar **from, gchar **join, gchar **where, GError **error)
 {
 	static     gboolean inited = FALSE;
 	ParserData data;
@@ -1222,9 +1225,9 @@
 	table_name = "Services";
 
 	data.sql_from = g_string_new ("");
-
 	g_string_append_printf (data.sql_from, "\n FROM %s S ", table_name);
 	
+	data.sql_join = g_string_new ("");
 	data.sql_where = g_string_new ("");
 
 	data.parser = g_new0 (GMarkupParser, 1);
@@ -1247,8 +1250,10 @@
 
 		g_string_free (data.sql_from, TRUE);
 		g_string_free (data.sql_where, TRUE);
+		g_string_free (data.sql_join, TRUE);
 
 		*from = NULL;
+		*join = NULL;
 		*where = NULL;
 
 	} else {
@@ -1257,7 +1262,7 @@
 		for (l = data.fields; l; l = l->next) {
 			if (!tracker_field_data_get_is_condition (l->data)) {
 				if (tracker_field_data_get_needs_join (l->data)) {
-					g_string_append_printf (data.sql_from, 
+					g_string_append_printf (data.sql_join, 
 								"\n LEFT OUTER JOIN %s %s ON (S.ID = %s.ServiceID and %s.MetaDataID = %s) ", 
 								tracker_field_data_get_table_name (l->data),
 								tracker_field_data_get_alias (l->data),
@@ -1270,7 +1275,7 @@
 
 				related_metadata = tracker_get_related_metadata_names (db_con, 
 										       tracker_field_data_get_field_name (l->data));
-				g_string_append_printf (data.sql_from, 
+				g_string_append_printf (data.sql_join, 
 							"\n INNER JOIN %s %s ON (S.ID = %s.ServiceID and %s.MetaDataID in (%s)) ",
 							tracker_field_data_get_table_name (l->data),
 							tracker_field_data_get_alias (l->data),
@@ -1282,10 +1287,13 @@
 		}
 
 		*from = g_strdup (data.sql_from->str);
+		*join = g_strdup (data.sql_join->str);
 		*where = g_strdup (data.sql_where->str);
 
 		g_string_free (data.sql_from, TRUE);
+		g_string_free (data.sql_join, TRUE);
 		g_string_free (data.sql_where, TRUE);
+		
 	}
 
 	g_slist_foreach (data.fields, (GFunc) g_object_unref, NULL);
@@ -1297,7 +1305,7 @@
 	if (data.current_field) {
 		g_free (data.current_field);
 	}
-
+	
 	if (data.current_value) {
 		g_free (data.current_value);
 	}

Modified: branches/indexer-split/src/trackerd/tracker-xesam-query.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-xesam-query.h	(original)
+++ branches/indexer-split/src/trackerd/tracker-xesam-query.h	Fri May 30 09:32:30 2008
@@ -28,7 +28,8 @@
 
 void                    tracker_xesam_query_to_sql          (DBConnection *db_con, 
                                                              const char   *query, 
-                                                             gchar       **from, 
+                                                             gchar       **from,
+							     gchar       **join,
                                                              gchar       **where, 
                                                              GError      **error);
 

Modified: branches/indexer-split/src/trackerd/tracker-xesam-session.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-xesam-session.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-xesam-session.c	Fri May 30 09:32:30 2008
@@ -76,7 +76,7 @@
 	priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,TRACKER_TYPE_XESAM_SESSION,struct _TrackerXesamSessionPriv);
 
 	g_ptr_array_add (ontos, dummy_onto);
-	
+
 	priv->session_id = NULL;
 
 



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