tracker r1581 - in branches/xesam-support: . src/trackerd
- From: mottela svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r1581 - in branches/xesam-support: . src/trackerd
- Date: Wed, 4 Jun 2008 16:13:03 +0000 (UTC)
Author: mottela
Date: Wed Jun 4 16:13:03 2008
New Revision: 1581
URL: http://svn.gnome.org/viewvc/tracker?rev=1581&view=rev
Log:
Initial xesam get_hits implementation
Modified:
branches/xesam-support/ChangeLog
branches/xesam-support/src/trackerd/tracker-db-sqlite.c
branches/xesam-support/src/trackerd/tracker-db-sqlite.h
branches/xesam-support/src/trackerd/tracker-xesam-live-search.c
Modified: branches/xesam-support/src/trackerd/tracker-db-sqlite.c
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-db-sqlite.c (original)
+++ branches/xesam-support/src/trackerd/tracker-db-sqlite.c Wed Jun 4 16:13:03 2008
@@ -1612,7 +1612,6 @@
valid = tracker_db_result_set_iter_next (result_set);
g_free (st);
}
-
g_object_unref (result_set);
return old_table;
@@ -2362,7 +2361,6 @@
return result_set;
}
-
char *
tracker_get_metadata_table (TrackerFieldType type)
{
@@ -3452,13 +3450,144 @@
}
+/* FIXME The following is redundant. Basically the same thing is done elsewhere and the code should be combined */
+static GList *
+add_metadata_field (DBConnection *db_con,
+ 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_exec_proc (db_con, "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 (db_con,
+ "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_get_live_search_get_hit_data (DBConnection *db_con, const gchar *search_id)
+tracker_db_get_live_search_get_hit_data (DBConnection *db_con, const gchar *search_id, gchar **field_names)
{
- return tracker_db_exec (db_con->db,
- "SELECT * FROM LiveSearches as X "
- "WHERE X.SearchID = '%s'",
- search_id);
+ TrackerDBResultSet *result;
+ GSList *fields = NULL;
+ GSList *l = NULL;
+
+ GString *sql_select;
+ GString *sql_join;
+ int i=0;
+
+ g_debug ("Get hit data");
+
+ sql_select = g_string_new ("");
+ sql_join = g_string_new ("");
+
+ while (field_names[i]) {
+ GList *field_data_list = NULL;
+ field_data_list = add_metadata_field (db_con, &fields, field_names[i]);
+
+ if (!field_data_list) {
+ g_warning ("Asking for a non-mapped xesam field: %s", field_names[i]);
+ 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_get_related_metadata_names (db_con,
+ 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 (db_con->db,
+ "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;
}
TrackerDBResultSet*
Modified: branches/xesam-support/src/trackerd/tracker-db-sqlite.h
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-db-sqlite.h (original)
+++ branches/xesam-support/src/trackerd/tracker-db-sqlite.h Wed Jun 4 16:13:03 2008
@@ -321,8 +321,8 @@
TrackerDBResultSet *tracker_get_xesam_metadata_names (DBConnection *db_con,
const char *name);
-TrackerDBResultSet *tracker_get_xesam_service_names (DBConnection *db_con,
- const char *name);
+TrackerDBResultSet *tracker_get_xesam_service_names (DBConnection *db_con,
+ const char *name);
gboolean tracker_db_load_xesam_service_file (TrackerDBInterface *iface,
const char *filename);
@@ -335,7 +335,8 @@
const gchar *where_query,
const gchar *search_id);
TrackerDBResultSet *tracker_db_get_live_search_get_hit_data (DBConnection *db_con,
- const gchar *search_id);
+ const gchar *search_id,
+ gchar **fields);
G_END_DECLS
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 Wed Jun 4 16:13:03 2008
@@ -545,11 +545,11 @@
static void
get_hit_data (TrackerXesamLiveSearch *self,
TrackerDBResultSet *result_set,
- GPtrArray **hit_data)
+ GPtrArray **hit_data,
+ gint field_count)
{
GPtrArray *result;
gboolean valid = TRUE;
- gint hitfields_columns = 0;
gint column;
result = g_ptr_array_new ();
@@ -557,9 +557,9 @@
while (valid) {
GPtrArray *row;
- row = g_ptr_array_new ();
+ row = g_ptr_array_new();
- for (column = 0; column < hitfields_columns; column++) {
+ for (column = 0; column < field_count; column++) {
GValue *value;
GValue value_in = {0, };
@@ -622,21 +622,35 @@
"Search is not active");
else {
TrackerDBResultSet *result_set = NULL;
+ TrackerXesamSession *session = priv->session;
DBConnection *db_con = NULL;
GObject *xesam;
+
+ GValue *value;
+ GStrv fields;
+ GError *tmp_error = NULL;
xesam = tracker_dbus_get_object (TRACKER_TYPE_XESAM);
g_object_get (xesam, "db-connection", &db_con, NULL);
g_debug ("live_search_get_hits");
+
+ tracker_xesam_session_get_property (session, "hit.fields", &value, &tmp_error);
- /* For ottela: fetch results for get_hits */
+ if (tmp_error) {
+ g_propagate_error(error, tmp_error);
+ return;
+ }
+
+ fields = g_value_get_boxed (value);
result_set = tracker_db_get_live_search_get_hit_data (db_con,
- tracker_xesam_live_search_get_id (self));
+ tracker_xesam_live_search_get_id (self), fields);
+ g_debug ("Got something from get_hit_data");
+
if (result_set) {
- get_hit_data (self, result_set, hits);
+ get_hit_data (self, result_set, hits, g_strv_length(fields));
g_object_unref (result_set);
}
}
@@ -663,19 +677,33 @@
"Search is not active");
} else {
TrackerDBResultSet *result_set = NULL;
+ TrackerXesamSession *session = priv->session;
DBConnection *db_con = NULL;
GObject *xesam;
+
+ GValue *value;
+ GStrv fields;
+ GError *tmp_error = NULL;
xesam = tracker_dbus_get_object (TRACKER_TYPE_XESAM);
g_object_get (xesam, "db-connection", &db_con, NULL);
- /* For ottela: fetch results for get_hits */
+ g_debug ("live_search_get_range_hits");
+
+ tracker_xesam_session_get_property (session, "hit.fields", &value, &tmp_error);
+
+ if (tmp_error) {
+ g_propagate_error(error, tmp_error);
+ return;
+ }
+
+ fields = g_value_get_boxed (value);
result_set = tracker_db_get_live_search_get_hit_data (db_con,
- tracker_xesam_live_search_get_id (self));
+ tracker_xesam_live_search_get_id (self), fields);
if (result_set) {
- get_hit_data (self, result_set, hits);
+ get_hit_data (self, result_set, hits, g_strv_length(fields));
g_object_unref (result_set);
}
}
@@ -736,13 +764,11 @@
xesam = tracker_dbus_get_object (TRACKER_TYPE_XESAM);
g_object_get (xesam, "db-connection", &db_con, NULL);
- /* For ottela: fetch results for get_hits */
-
result_set = tracker_db_get_live_search_get_hit_data (db_con,
- tracker_xesam_live_search_get_id (self));
+ tracker_xesam_live_search_get_id (self), fields);
if (result_set) {
- get_hit_data (self, result_set, hit_data);
+ get_hit_data (self, result_set, hit_data, g_strv_length (fields));
g_object_unref (result_set);
}
}
@@ -774,16 +800,15 @@
DBConnection *db_con = NULL;
GObject *xesam;
+
xesam = tracker_dbus_get_object (TRACKER_TYPE_XESAM);
g_object_get (xesam, "db-connection", &db_con, NULL);
- /* For ottela: fetch results for get_hits */
-
result_set = tracker_db_get_live_search_get_hit_data (db_con,
- tracker_xesam_live_search_get_id (self));
+ tracker_xesam_live_search_get_id (self), fields);
if (result_set) {
- get_hit_data (self, result_set, hit_data);
+ get_hit_data (self, result_set, hit_data, g_strv_length(fields));
g_object_unref (result_set);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]