tracker r2007 - in branches/indexer-split: . data/services src/tracker-indexer src/trackerd
- From: ifrade svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2007 - in branches/indexer-split: . data/services src/tracker-indexer src/trackerd
- Date: Tue, 5 Aug 2008 15:12:00 +0000 (UTC)
Author: ifrade
Date: Tue Aug 5 15:12:00 2008
New Revision: 2007
URL: http://svn.gnome.org/viewvc/tracker?rev=2007&view=rev
Log:
Handling multiple values in the property set/remove property API of the indexer
Modified:
branches/indexer-split/ChangeLog
branches/indexer-split/data/services/default.metadata
branches/indexer-split/src/tracker-indexer/tracker-indexer-db.c
branches/indexer-split/src/tracker-indexer/tracker-indexer-db.h
branches/indexer-split/src/tracker-indexer/tracker-indexer.c
branches/indexer-split/src/trackerd/tracker-keywords.c
branches/indexer-split/src/trackerd/tracker-metadata.c
Modified: branches/indexer-split/data/services/default.metadata
==============================================================================
--- branches/indexer-split/data/services/default.metadata (original)
+++ branches/indexer-split/data/services/default.metadata Tue Aug 5 15:12:00 2008
@@ -109,5 +109,6 @@
Weight=50
Embedded=false
MultipleValues=true
+Filtered=false
Modified: branches/indexer-split/src/tracker-indexer/tracker-indexer-db.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-indexer-db.c (original)
+++ branches/indexer-split/src/tracker-indexer/tracker-indexer-db.c Tue Aug 5 15:12:00 2008
@@ -25,7 +25,7 @@
#include <libtracker-common/tracker-type-utils.h>
#include <libtracker-db/tracker-db-manager.h>
-
+#include <libtracker-db/tracker-db-dbus.h>
#include "tracker-indexer-db.h"
@@ -338,6 +338,89 @@
return db_get_metadata (service, service_id, FALSE);
}
+gchar **
+tracker_db_get_property_values (TrackerService *service_def,
+ guint32 id,
+ TrackerField *field_def)
+{
+ TrackerDBInterface *iface;
+ TrackerDBResultSet *result_set;
+ gint metadata_key;
+ gchar **final_result = NULL;
+ gboolean is_numeric = FALSE;
+
+ iface = tracker_db_manager_get_db_interface_by_type (tracker_service_get_name (service_def),
+ TRACKER_DB_CONTENT_TYPE_METADATA);
+
+ metadata_key = tracker_ontology_metadata_key_in_service (tracker_service_get_name (service_def),
+ tracker_field_get_name (field_def));
+ if (metadata_key > 0) {
+ gchar *query = g_strdup_printf ("SELECT KeyMetadata%d FROM Services WHERE id = '%d'",
+ metadata_key, id);
+ result_set = tracker_db_interface_execute_query (iface, NULL, query, NULL);
+ g_free (query);
+ } else {
+ gchar *id_str;
+
+ id_str = tracker_guint32_to_string (id);
+
+ switch (tracker_field_get_data_type (field_def)) {
+ case TRACKER_FIELD_TYPE_KEYWORD:
+ result_set = tracker_db_interface_execute_procedure (iface, NULL,
+ "GetMetadataKeyword",
+ id_str,
+ tracker_field_get_id (field_def),
+ NULL);
+ break;
+ case TRACKER_FIELD_TYPE_INDEX:
+ case TRACKER_FIELD_TYPE_STRING:
+ case TRACKER_FIELD_TYPE_DOUBLE:
+ result_set = tracker_db_interface_execute_procedure (iface, NULL,
+ "GetMetadata",
+ id_str,
+ tracker_field_get_id (field_def),
+ NULL);
+ break;
+ case TRACKER_FIELD_TYPE_INTEGER:
+ case TRACKER_FIELD_TYPE_DATE:
+ result_set = tracker_db_interface_execute_procedure (iface, NULL,
+ "GetMetadataNumeric",
+ id_str,
+ tracker_field_get_id (field_def),
+ NULL);
+ is_numeric = TRUE;
+ break;
+ case TRACKER_FIELD_TYPE_FULLTEXT:
+ tracker_db_get_text (service_def, id);
+ break;
+ case TRACKER_FIELD_TYPE_BLOB:
+ case TRACKER_FIELD_TYPE_STRUCT:
+ case TRACKER_FIELD_TYPE_LINK:
+ /* not handled */
+ default:
+ break;
+ }
+ g_free (id_str);
+ }
+
+ if (result_set) {
+
+ if (tracker_db_result_set_get_n_rows (result_set) > 1) {
+ g_warning ("More than one result in tracker_db_get_property_value");
+ }
+
+ if (!is_numeric) {
+ final_result = tracker_dbus_query_result_to_strv (result_set, 0, NULL);
+ } else {
+ final_result = tracker_dbus_query_result_numeric_to_strv (result_set, 0, NULL);
+ }
+
+ g_object_unref (result_set);
+ }
+
+ return final_result;
+}
+
void
tracker_db_set_metadata (TrackerService *service,
@@ -422,7 +505,12 @@
switch (tracker_field_get_data_type (field)) {
case TRACKER_FIELD_TYPE_KEYWORD:
if (!value) {
- g_warning ("Trying to remove keyword field with no specific value");
+ g_debug ("Trying to remove keyword field with no specific value");
+ tracker_db_interface_execute_procedure (iface, NULL,
+ "DeleteMetadataKeyword",
+ id_str,
+ tracker_field_get_id (field),
+ NULL);
} else {
tracker_db_interface_execute_procedure (iface, NULL,
"DeleteMetadataKeywordValue",
Modified: branches/indexer-split/src/tracker-indexer/tracker-indexer-db.h
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-indexer-db.h (original)
+++ branches/indexer-split/src/tracker-indexer/tracker-indexer-db.h Tue Aug 5 15:12:00 2008
@@ -59,13 +59,15 @@
guint32 id);
gchar *tracker_db_get_unparsed_metadata (TrackerService *service,
guint32 id);
+gchar **tracker_db_get_property_values (TrackerService *service_def,
+ guint32 id,
+ TrackerField *field_def);
void tracker_db_delete_all_metadata (TrackerService *service,
guint32 id);
void tracker_db_delete_metadata (TrackerService *service,
guint32 id,
TrackerField *field,
const gchar *value);
-
/* Contents */
void tracker_db_set_text (TrackerService *service,
guint32 id,
Modified: branches/indexer-split/src/tracker-indexer/tracker-indexer.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-indexer.c (original)
+++ branches/indexer-split/src/tracker-indexer/tracker-indexer.c Tue Aug 5 15:12:00 2008
@@ -851,6 +851,10 @@
GList *words = NULL, *iter;
gint weight;
+ if (!text) {
+ return;
+ }
+
if (full_parsing) {
parsed = tracker_parser_text (parsed,
text,
@@ -1069,6 +1073,23 @@
return FALSE;
}
+ if (tracker_field_get_embedded (field_def)) {
+ g_set_error (error,
+ g_quark_from_string (TRACKER_INDEXER_ERROR),
+ TRACKER_INDEXER_ERROR_CODE,
+ "Field type: '%s' is embedded and not writable", property);
+ return FALSE;
+ }
+
+ if (!tracker_field_get_multiple_values (field_def) && g_strv_length (values) > 1) {
+ g_set_error (error,
+ g_quark_from_string (TRACKER_INDEXER_ERROR),
+ TRACKER_INDEXER_ERROR_CODE,
+ "Field type: '%s' doesnt support multiple values (trying to set %d)",
+ property, g_strv_length (values));
+ return FALSE;
+ }
+
dirname = tracker_file_get_vfs_path (uri);
basename = tracker_file_get_vfs_name (uri);
@@ -1085,12 +1106,43 @@
return FALSE;
}
+ if (!tracker_field_get_multiple_values (field_def)) {
+
+ /* Remove old value from DB and index */
+ gchar **old_contents;
+
+ old_contents = tracker_db_get_property_values (service_def, service_id, field_def);
+ if (old_contents && g_strv_length (old_contents) > 1) {
+ g_critical ("Seems to be multiple values in a field that doesn allow that ('%s')",
+ tracker_field_get_name (field_def));
+
+ } else if (old_contents && g_strv_length (old_contents) == 1) {
+
+ if (tracker_field_get_filtered (field_def)) {
+ unindex_text_with_parsing (indexer,
+ service_id,
+ tracker_service_get_id (service_def),
+ old_contents[0],
+ tracker_field_get_weight (field_def));
+ } else {
+ unindex_text_no_parsing (indexer,
+ service_id,
+ tracker_service_get_id (service_def),
+ old_contents[0],
+ tracker_field_get_weight (field_def));
+ }
+ tracker_db_delete_metadata (service_def, service_id, field_def, old_contents[0]);
+ g_strfreev (old_contents);
+ }
+ }
+
for (i = 0; values[i] != NULL; i++) {
g_debug ("Setting metadata: service_type '%s' id '%d' field '%s' value '%s'",
tracker_service_get_name (service_def),
service_id,
tracker_field_get_name (field_def),
values[i]);
+
tracker_db_set_metadata (service_def,
service_id,
field_def,
@@ -1099,11 +1151,19 @@
}
joined = g_strjoinv (" ", values);
- index_text_no_parsing (indexer,
- service_id,
- tracker_service_get_id (service_def),
- joined,
- tracker_field_get_weight (field_def));
+ if (tracker_field_get_filtered (field_def)) {
+ index_text_no_parsing (indexer,
+ service_id,
+ tracker_service_get_id (service_def),
+ joined,
+ tracker_field_get_weight (field_def));
+ } else {
+ index_text_with_parsing (indexer,
+ service_id,
+ tracker_service_get_id (service_def),
+ joined,
+ tracker_field_get_weight (field_def));
+ }
g_free (joined);
return TRUE;
@@ -1121,7 +1181,7 @@
TrackerService *service_def;
TrackerField *field_def;
guint service_id, i;
- gchar *joined, *dirname, *basename;
+ gchar *joined = NULL, *dirname, *basename;
service_def = tracker_ontology_get_service_type_by_name (service_type);
if (!service_def) {
@@ -1141,6 +1201,14 @@
return FALSE;
}
+ if (tracker_field_get_embedded (field_def)) {
+ g_set_error (error,
+ g_quark_from_string (TRACKER_INDEXER_ERROR),
+ TRACKER_INDEXER_ERROR_CODE,
+ "Field type: '%s' is embedded and cannot be deleted", property);
+ return FALSE;
+ }
+
dirname = tracker_file_get_vfs_path (uri);
basename = tracker_file_get_vfs_name (uri);
@@ -1157,21 +1225,50 @@
return FALSE;
}
+ /*
+ * If we receive concrete values, we delete those rows in the db
+ * Otherwise, retrieve the old values of the property and remove all their instances for the file
+ */
+ if (g_strv_length (values) > 0) {
+ for (i = 0; values[i] != NULL; i++) {
+ tracker_db_delete_metadata (service_def,
+ service_id,
+ field_def,
+ values[i]);
+ }
+ joined = g_strjoinv (" ", values);
+ } else {
+ gchar **old_contents;
+
+ old_contents = tracker_db_get_property_values (service_def, service_id, field_def);
+ if (old_contents) {
+ tracker_db_delete_metadata (service_def,
+ service_id,
+ field_def,
+ NULL);
+
+ joined = g_strjoinv (" ", old_contents);
+ g_strfreev (old_contents);
+ }
+ }
-
- for (i = 0; values[i] != NULL; i++) {
- tracker_db_delete_metadata (service_def,
- service_id,
- field_def,
- values[i]);
+ /*
+ * Now joined contains the words to unindex
+ */
+ if (tracker_field_get_filtered (field_def)) {
+ unindex_text_with_parsing (indexer,
+ service_id,
+ tracker_service_get_id (service_def),
+ joined,
+ tracker_field_get_weight (field_def));
+ } else {
+ unindex_text_no_parsing (indexer,
+ service_id,
+ tracker_service_get_id (service_def),
+ joined,
+ tracker_field_get_weight (field_def));
}
- joined = g_strjoinv (" ", values);
- unindex_text_no_parsing (indexer,
- service_id,
- tracker_service_get_id (service_def),
- joined,
- tracker_field_get_weight (field_def));
g_free (joined);
return TRUE;
@@ -1644,11 +1741,11 @@
tracker_dbus_async_return_if_fail (service_type != NULL, FALSE);
tracker_dbus_async_return_if_fail (uri != NULL, FALSE);
tracker_dbus_async_return_if_fail (property != NULL, FALSE);
- /* Values can be NULL */
+ tracker_dbus_async_return_if_fail (values != NULL, FALSE);
tracker_dbus_request_new (request_id,
- "DBus request to remove %s values in property '%s' for file '%s' ",
- ( values == NULL ? "all" : g_strdup_printf ("%d", g_strv_length (values))),
+ "DBus request to remove %d values in property '%s' for file '%s' ",
+ g_strv_length (values),
property,
uri);
Modified: branches/indexer-split/src/trackerd/tracker-keywords.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-keywords.c (original)
+++ branches/indexer-split/src/trackerd/tracker-keywords.c Tue Aug 5 15:12:00 2008
@@ -322,14 +322,14 @@
{
TrackerDBInterface *iface;
guint request_id;
- gchar *id;
+ gchar *service_id, *service_result = NULL;
GError *actual_error = NULL;
request_id = tracker_dbus_get_next_request_id ();
tracker_dbus_async_return_if_fail (service_type != NULL, FALSE);
tracker_dbus_async_return_if_fail (uri != NULL, FALSE);
- tracker_dbus_async_return_if_fail (keywords != NULL && *keywords != NULL, FALSE);
+ tracker_dbus_async_return_if_fail (keywords != NULL && g_strv_length (keywords) > 0, FALSE);
tracker_dbus_request_new (request_id,
"DBus request to remove keywords, "
@@ -356,9 +356,10 @@
return;
}
+ /* Check the uri exists, so we dont start the indexer in vain */
iface = tracker_db_manager_get_db_interface_by_service (service_type);
- id = tracker_db_file_get_id_as_string (iface, service_type, uri);
- if (!id) {
+ service_id = tracker_db_file_get_id_as_string (iface, service_type, uri);
+ if (!service_id) {
tracker_dbus_request_failed (request_id,
&actual_error,
"Entity '%s' was not found",
@@ -368,9 +369,8 @@
return;
}
-
org_freedesktop_Tracker_Indexer_property_remove (tracker_dbus_indexer_get_proxy (),
- service_type,
+ service_result,
uri,
"User:Keywords",
(const gchar **)keywords,
@@ -385,7 +385,7 @@
return;
}
- g_free (id);
+ g_free (service_id);
dbus_g_method_return (context);
@@ -400,10 +400,9 @@
GError **error)
{
TrackerDBInterface *iface;
- TrackerDBResultSet *result_set;
guint request_id;
- gchar *id;
gchar **values;
+ gchar *service_id;
GError *actual_error = NULL;
request_id = tracker_dbus_get_next_request_id ();
@@ -436,9 +435,10 @@
return;
}
+ /* Check the uri exists, so we dont start the indexer in vain */
iface = tracker_db_manager_get_db_interface_by_service (service_type);
- id = tracker_db_file_get_id_as_string (iface, service_type, uri);
- if (!id) {
+ service_id = tracker_db_file_get_id_as_string (iface, service_type, uri);
+ if (!service_id) {
tracker_dbus_request_failed (request_id,
&actual_error,
"Entity '%s' was not found",
@@ -448,11 +448,8 @@
return;
}
- result_set = tracker_db_metadata_get (iface,
- id,
- "User:Keywords");
- values = tracker_dbus_query_result_to_strv (result_set, 0, NULL);
-
+ values = g_new0 (gchar *, 1);
+ values[0] = NULL;
org_freedesktop_Tracker_Indexer_property_remove (tracker_dbus_indexer_get_proxy (),
service_type,
uri,
@@ -460,6 +457,7 @@
(const gchar **)values,
&actual_error);
+ g_strfreev (values);
if (actual_error) {
tracker_dbus_request_failed (request_id,
&actual_error,
@@ -469,8 +467,6 @@
return;
}
- g_strfreev (values);
- g_free (id);
dbus_g_method_return (context);
Modified: branches/indexer-split/src/trackerd/tracker-metadata.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-metadata.c (original)
+++ branches/indexer-split/src/trackerd/tracker-metadata.c Tue Aug 5 15:12:00 2008
@@ -127,6 +127,8 @@
/* The parameter service_type can be "Files"
* and the actual service type of the uri "Video"
+ *
+ * Note: Does this matter?
*/
service_result = tracker_db_service_get_by_entity (iface, service_id);
if (!service_result) {
@@ -171,7 +173,7 @@
{
TrackerDBInterface *iface;
guint request_id;
- gchar *service_id, *service_result;
+ gchar *service_id;
guint i;
GError *actual_error = NULL;
@@ -201,6 +203,7 @@
iface = tracker_db_manager_get_db_interface_by_service (service_type);
+ /* Check the uri exists, so we dont start the indexer in vain */
service_id = tracker_db_file_get_id_as_string (iface, service_type, uri);
if (!service_id) {
tracker_dbus_request_failed (request_id,
@@ -212,21 +215,6 @@
return;
}
- /* The parameter service_type can be "Files"
- * and the actual service type of the uri "Video"
- */
- service_result = tracker_db_service_get_by_entity (iface, service_id);
- if (!service_result) {
- g_free (service_id);
- tracker_dbus_request_failed (request_id,
- &actual_error,
- "Service type can not be found for entity '%s'",
- uri);
- dbus_g_method_return_error (context, actual_error);
- g_error_free (actual_error);
- return;
- }
-
/* Checking keys */
for (i = 0; i < g_strv_length (keys); i++) {
TrackerField *field_def;
@@ -256,14 +244,14 @@
value = tracker_string_to_string_list (values[i]);
org_freedesktop_Tracker_Indexer_property_set (tracker_dbus_indexer_get_proxy (),
- service_result,
+ service_type,
uri,
keys[i],
- (const gchar **)value, //As gchar **
+ (const gchar **)value,
&actual_error);
g_strfreev (value);
if (actual_error) {
- /* tracker_dbus_request_failes -> find a way to propagate the error */
+ tracker_dbus_request_failed (request_id, &actual_error, NULL);
dbus_g_method_return_error (context, actual_error);
g_error_free (actual_error);
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]