tracker r2335 - in trunk: . src/libtracker-common src/trackerd tests/libtracker-common
- From: ifrade svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2335 - in trunk: . src/libtracker-common src/trackerd tests/libtracker-common
- Date: Wed, 8 Oct 2008 18:20:22 +0000 (UTC)
Author: ifrade
Date: Wed Oct 8 18:20:22 2008
New Revision: 2335
URL: http://svn.gnome.org/viewvc/tracker?rev=2335&view=rev
Log:
Calculating subcategories of a category in tracker-ontology
Modified:
trunk/ChangeLog
trunk/src/libtracker-common/tracker-ontology.c
trunk/src/libtracker-common/tracker-ontology.h
trunk/src/trackerd/tracker-db.c
trunk/tests/libtracker-common/tracker-ontology-test.c
Modified: trunk/src/libtracker-common/tracker-ontology.c
==============================================================================
--- trunk/src/libtracker-common/tracker-ontology.c (original)
+++ trunk/src/libtracker-common/tracker-ontology.c Wed Oct 8 18:20:22 2008
@@ -51,6 +51,9 @@
/* FieldType enum class */
static gpointer field_type_enum_class;
+/* Category - subcategory ids cache */
+static GHashTable *subcategories_cache;
+
static void
ontology_mime_prefix_foreach (gpointer data,
gpointer user_data)
@@ -112,6 +115,12 @@
return data;
}
+static void
+free_int_array (gpointer data)
+{
+ g_array_free ((GArray *)data, TRUE);
+}
+
void
tracker_ontology_init (void)
{
@@ -139,6 +148,11 @@
g_free,
g_object_unref);
+ subcategories_cache = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ free_int_array);
+
/* We will need the class later in order to match strings to enum values
* when inserting metadata types in the DB, so the enum class needs to be
* created beforehand.
@@ -167,6 +181,9 @@
g_hash_table_unref (field_names);
field_names = NULL;
+ g_hash_table_unref (subcategories_cache);
+ subcategories_cache = NULL;
+
if (service_mime_prefixes) {
g_slist_foreach (service_mime_prefixes,
ontology_mime_prefix_foreach,
@@ -453,6 +470,51 @@
return names;
}
+typedef struct {
+ gchar *name;
+ GArray *subcategories;
+} CalculateSubcategoriesForEach;
+
+static void
+calculate_subcategories_foreach (gpointer key, gpointer value, gpointer user_data)
+{
+ TrackerService *service_def;
+ CalculateSubcategoriesForEach *data;
+
+ service_def = (TrackerService *)value;
+ data = (CalculateSubcategoriesForEach *)user_data;
+
+ if (!g_strcmp0 (tracker_service_get_name (service_def), data->name)
+ || !g_strcmp0 (tracker_service_get_parent (service_def), data->name)
+ || !g_strcmp0 ("*", data->name)) {
+ gint id = tracker_service_get_id (service_def);
+ g_array_append_val (data->subcategories, id);
+ }
+}
+
+GArray *
+tracker_ontology_get_subcategory_ids (const gchar *service_str)
+{
+ GArray *subcategories;
+
+ subcategories = g_hash_table_lookup (subcategories_cache, service_str);
+
+ if (!subcategories) {
+ CalculateSubcategoriesForEach data;
+
+ data.name = g_strdup (service_str);
+ data.subcategories = g_array_new (TRUE, TRUE, sizeof (int));
+
+ g_hash_table_foreach (service_names, calculate_subcategories_foreach, &data);
+
+ g_hash_table_insert (subcategories_cache, data.name, data.subcategories);
+
+ subcategories = data.subcategories;
+ }
+
+ return subcategories;
+}
+
/*
* Service data
*/
Modified: trunk/src/libtracker-common/tracker-ontology.h
==============================================================================
--- trunk/src/libtracker-common/tracker-ontology.h (original)
+++ trunk/src/libtracker-common/tracker-ontology.h Wed Oct 8 18:20:22 2008
@@ -50,6 +50,7 @@
gint tracker_ontology_get_service_parent_id_by_id (gint id);
GSList * tracker_ontology_get_service_names_registered (void);
GSList * tracker_ontology_get_field_names_registered (const gchar *service_str);
+GArray * tracker_ontology_get_subcategory_ids (const gchar *service_str);
/* Service data */
gboolean tracker_ontology_service_is_valid (const gchar *service_str);
Modified: trunk/src/trackerd/tracker-db.c
==============================================================================
--- trunk/src/trackerd/tracker-db.c (original)
+++ trunk/src/trackerd/tracker-db.c Wed Oct 8 18:20:22 2008
@@ -106,72 +106,15 @@
gboolean basic_services)
{
GArray *array;
- gint services[16];
- 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;
- }
+ array = tracker_ontology_get_subcategory_ids (service);
} else if (basic_services) {
- add_files = TRUE;
- add_emails = FALSE;
- add_conversations = FALSE;
+ array = tracker_ontology_get_subcategory_ids ("Files");
} else {
- add_files = TRUE;
- add_emails = TRUE;
- add_conversations = TRUE;
+ array = tracker_ontology_get_subcategory_ids ("*");
}
- count = 0;
-
- if (add_files) {
- services[count++] = tracker_ontology_get_service_id_by_name ("Files");
- services[count++] = tracker_ontology_get_service_id_by_name ("Applications");
- services[count++] = tracker_ontology_get_service_id_by_name ("Playlists");
- services[count++] = tracker_ontology_get_service_id_by_name ("Folders");
- services[count++] = tracker_ontology_get_service_id_by_name ("Documents");
- services[count++] = tracker_ontology_get_service_id_by_name ("Images");
- services[count++] = tracker_ontology_get_service_id_by_name ("Videos");
- services[count++] = tracker_ontology_get_service_id_by_name ("Music");
- services[count++] = tracker_ontology_get_service_id_by_name ("Text");
- services[count++] = tracker_ontology_get_service_id_by_name ("Development");
- services[count++] = tracker_ontology_get_service_id_by_name ("Other");
- }
-
- if (add_emails) {
- services[count++] = tracker_ontology_get_service_id_by_name ("EvolutionEmails");
- services[count++] = tracker_ontology_get_service_id_by_name ("KMailEmails");
- services[count++] = tracker_ontology_get_service_id_by_name ("ThunderbirdEmails");
- }
-
- if (add_conversations) {
- services[count++] = tracker_ontology_get_service_id_by_name ("GaimConversations");
- }
-
- services[count] = 0;
-
- array = g_array_new (TRUE, TRUE, sizeof (gint));
- g_array_append_vals (array, services, count);
-
return array;
}
@@ -331,7 +274,6 @@
GArray *hits;
gint count;
gboolean detailed_emails = FALSE, detailed_apps = FALSE;
- gint service_array[255];
const gchar *procedure;
GArray *services = NULL;
GSList *duds = NULL;
@@ -350,30 +292,7 @@
tracker_config_get_max_word_length (private->config),
tracker_config_get_min_word_length (private->config));
- result_set = tracker_db_exec_proc (iface,
- "GetRelatedServiceIDs",
- service,
- service,
- NULL);
-
- if (result_set) {
- gboolean valid = TRUE;
- gint type_id;
-
- while (valid) {
- tracker_db_result_set_get (result_set, 0, &type_id, -1);
- service_array[i] = type_id;
- i++;
-
- valid = tracker_db_result_set_iter_next (result_set);
- }
-
- service_array[i] = 0;
- services = g_array_new (TRUE, TRUE, sizeof (gint));
- g_array_append_vals (services, service_array, i);
- g_object_unref (result_set);
- }
-
+ services = tracker_db_create_array_of_services (service, FALSE);
/* FIXME: Do we need both index and services here? We used to have it */
tree = tracker_query_tree_new (search_string,
private->config,
@@ -505,7 +424,6 @@
g_object_unref (tree);
g_array_free (hits, TRUE);
- g_array_free (services, TRUE);
if (!result) {
return NULL;
@@ -602,7 +520,6 @@
g_object_unref (tree);
g_array_free (hits, TRUE);
- g_array_free (services, TRUE);
if (!result_set1) {
return NULL;
@@ -702,7 +619,6 @@
g_free (location_prefix);
g_object_unref (tree);
g_array_free (hits, TRUE);
- g_array_free (services, TRUE);
if (!result_set1) {
return NULL;
@@ -809,7 +725,6 @@
g_free (location_prefix);
g_object_unref (tree);
g_array_free (hits, TRUE);
- g_array_free (services, TRUE);
if (!result_set1) {
return NULL;
Modified: trunk/tests/libtracker-common/tracker-ontology-test.c
==============================================================================
--- trunk/tests/libtracker-common/tracker-ontology-test.c (original)
+++ trunk/tests/libtracker-common/tracker-ontology-test.c Wed Oct 8 18:20:22 2008
@@ -384,6 +384,30 @@
g_assert_cmpint (key, ==, 0);
}
+static void
+test_get_subcategories (void)
+{
+ GArray *result;
+
+ result = tracker_ontology_get_subcategory_ids ("Applications");
+
+ g_assert_cmpint (result->len, ==, 1);
+
+ result = tracker_ontology_get_subcategory_ids ("Conversations");
+/*
+ Conversations, GaimConversations, GossipConversations
+ FIXME implement more than one level of hierarchy!
+*/
+ g_assert_cmpint (result->len, ==, 3);
+
+
+ result = tracker_ontology_get_subcategory_ids ("*");
+
+ g_assert_cmpint (result->len, ==, 7);
+
+ g_array_free (result, TRUE);
+}
+
int
main (int argc, char **argv)
{
@@ -429,6 +453,9 @@
g_test_add_func ("/libtracker-common/tracker-ontology/test_metadata_key_in_service",
test_metadata_key_in_service);
+ g_test_add_func ("/libtracker-common/tracker-ontology/test_get_subcategories",
+ test_get_subcategories);
+
result = g_test_run ();
tracker_ontology_shutdown ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]