tracker r1614 - branches/xesam-support/src/trackerd



Author: mottela
Date: Mon Jun  9 18:58:11 2008
New Revision: 1614
URL: http://svn.gnome.org/viewvc/tracker?rev=1614&view=rev

Log:
Some fixes to problems caused by the merge

Modified:
   branches/xesam-support/src/trackerd/tracker-db.c
   branches/xesam-support/src/trackerd/tracker-xesam-live-search.c

Modified: branches/xesam-support/src/trackerd/tracker-db.c
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-db.c	(original)
+++ branches/xesam-support/src/trackerd/tracker-db.c	Mon Jun  9 18:58:11 2008
@@ -2249,18 +2249,151 @@
 	return result_set;
 }
 
+// FIXME This function should be moved with other help-functions somewhere. It is used by xesam_live_search parsing.
+static GList *
+add_metadata_field (TrackerDBInterface *iface,
+		    GSList **fields, 
+		    const char *xesam_name)
+{
+	TrackerDBResultSet *result_set;
+	TrackerFieldData   *field_data;
+	gboolean            field_exists;
+	const GSList       *l;
+	GList              *reply;
+	gboolean            valid;
+
+	reply = NULL;
+	field_exists = FALSE;
+	field_data = NULL;
+	valid = TRUE;
+
+	/* Do the xesam mapping */
+	
+	g_debug ("add metadata field");
+
+	result_set = tracker_db_exec_proc (iface, "GetXesamMetaDataMappings",xesam_name, NULL);
+
+	if (!result_set) {
+		return NULL;
+	}
+
+	while (valid) {
+		gchar *field_name;
+		
+		tracker_db_result_set_get (result_set, 0, &field_name, -1);
+
+		/* Check if field is already in list */
+		for (l = *fields; l; l = l->next) {
+			const gchar *this_field_name;
+			
+			this_field_name = tracker_field_data_get_field_name (l->data);
+			
+			if (!this_field_name) {
+				continue;
+			}
+				
+			if (strcasecmp (this_field_name, field_name) != 0) {
+				continue;
+			}
+
+			field_exists = TRUE;		       
+			
+			break;
+		}
+		
+		if (!field_exists) {
+			field_data = tracker_db_get_metadata_field (iface, 
+								    "Files", 
+								    field_name, 
+								    g_slist_length (*fields),
+								    FALSE, 
+								    FALSE);
+
+			if (field_data) {
+				*fields = g_slist_prepend (*fields, field_data);
+			} 
+		} 
+		
+		reply = g_list_append (reply, field_data);
+		valid = tracker_db_result_set_iter_next (result_set);
+		g_free (field_name);
+	}
+	
+	return reply;
+}
+
+
+
 TrackerDBResultSet *
 tracker_db_live_search_get_hit_data (TrackerDBInterface *iface, 
 				     const gchar        *search_id,
-				     GStrv               fields)
+				     GStrv               field_names)
 {
+	TrackerDBResultSet *result;
+	GSList *fields = NULL;
+	GSList *l = NULL;
+
+	GString *sql_select;
+	GString *sql_join;
+	int i=0;
+
 	g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
 	g_return_val_if_fail (search_id != NULL, NULL);
+	g_return_val_if_fail (fields != NULL, NULL);
+
+	sql_select = g_string_new ("");
+	sql_join = g_string_new ("");
 
-	return tracker_db_exec (iface, 
-				"SELECT * FROM LiveSearches as X "
-				"WHERE X.SearchID = '%s'", 
-				search_id);
+	while (field_names[i]) {
+		GList *field_data_list = NULL;
+		field_data_list = add_metadata_field (iface, &fields, field_names[i]);
+
+		if (!field_data_list) {
+			g_warning ("Asking for a non-mapped xesam field: %s", field_names[i]);
+			g_string_free (sql_select, TRUE);
+			g_string_free (sql_join, TRUE);
+			return NULL;
+		}
+		
+		if (i) {
+			g_string_append_printf (sql_select, ",");
+		}
+
+		g_string_append_printf (sql_select, "%s ", tracker_field_data_get_select_field (field_data_list->data) );
+		
+		i++;
+	}
+
+	for (l = fields; l; l = l->next) {
+		gchar *field_name;		
+
+		field_name = tracker_db_metadata_get_related_names (iface, 
+								    tracker_field_data_get_field_name (l->data));
+		g_string_append_printf (sql_join, 
+					"INNER JOIN %s %s ON (X.ServiceID = %s.ServiceID AND %s.MetaDataID in (%s))\n ",
+					tracker_field_data_get_table_name (l->data),
+					tracker_field_data_get_alias (l->data),
+					tracker_field_data_get_alias (l->data),
+					tracker_field_data_get_alias (l->data),
+					field_name);
+		g_free (field_name);
+	}
+
+	g_debug("Query : SELECT %s FROM LiveSearches as X \n"
+		"%s"
+		"WHERE X.SearchID = '%s'", 
+		sql_select->str, sql_join->str, search_id); 
+
+	result = tracker_db_exec (iface, 
+				  "SELECT %s FROM LiveSearches as X \n"
+				  "%s"
+				  "WHERE X.SearchID = '%s'", 
+				  sql_select->str, sql_join->str, search_id);
+
+	g_string_free (sql_select, TRUE);
+	g_string_free (sql_join, TRUE);
+
+	return result;
 }
 
 void 

Modified: branches/xesam-support/src/trackerd/tracker-xesam-live-search.c
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-xesam-live-search.c	(original)
+++ branches/xesam-support/src/trackerd/tracker-xesam-live-search.c	Mon Jun  9 18:58:11 2008
@@ -732,6 +732,8 @@
 	g_return_if_fail (TRACKER_IS_XESAM_LIVE_SEARCH (self));
 	g_return_if_fail (hits != NULL);
 
+	g_debug ("Get_hits called");
+
 	priv = self->priv;
 
 	if (!priv->active)
@@ -1013,6 +1015,8 @@
 		TrackerDBInterface *iface;
 		GArray             *hits;
 
+		g_debug ("* * * Activate");
+
 		iface = tracker_db_manager_get_db_interface (TRACKER_DB_XESAM);
 
 		tracker_db_live_search_start (iface,
@@ -1178,8 +1182,9 @@
 		g_free (orig_where);
 	}
 
-	g_message ("Parsed to '%s' and '%s'", 
-		   priv->from_sql, 
+	g_message ("Parsed to '%s', '%s' and '%s'", 
+		   priv->from_sql,
+		   priv->join_sql,
 		   priv->where_sql);
 
 	return TRUE;



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