tracker r2443 - in trunk: . src/trackerd
- From: ifrade svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2443 - in trunk: . src/trackerd
- Date: Tue, 4 Nov 2008 13:38:00 +0000 (UTC)
Author: ifrade
Date: Tue Nov 4 13:38:00 2008
New Revision: 2443
URL: http://svn.gnome.org/viewvc/tracker?rev=2443&view=rev
Log:
Implemented method search.Metadata
Modified:
trunk/ChangeLog
trunk/src/trackerd/tracker-rdf-query.c
trunk/src/trackerd/tracker-rdf-query.h
trunk/src/trackerd/tracker-search.c
Modified: trunk/src/trackerd/tracker-rdf-query.c
==============================================================================
--- trunk/src/trackerd/tracker-rdf-query.c (original)
+++ trunk/src/trackerd/tracker-rdf-query.c Tue Nov 4 13:38:00 2008
@@ -1506,3 +1506,51 @@
g_free (data.parser);
}
+
+gchar *
+tracker_rdf_query_for_attr_value (const gchar *field,
+ const gchar *value)
+{
+ TrackerField *field_def;
+ const gchar *CONDITION_OPEN = "<rdfq:Condition><rdfq:equals>";
+ const gchar *CONDITION_CLOSE = "</rdfq:equals></rdfq:Condition>";
+ gchar *CLAUSE = g_strdup_printf ("<rdfq:Property name=\"%s\"/>", field);
+ gchar *rdf_type, *rdf_value;
+
+ gchar *rdf_query;
+
+ field_def = tracker_ontology_get_field_by_name (field);
+
+ if (!field_def) {
+ return NULL;
+ }
+
+ switch (tracker_field_get_data_type (field_def)) {
+ case TRACKER_FIELD_TYPE_KEYWORD:
+ case TRACKER_FIELD_TYPE_INDEX:
+ case TRACKER_FIELD_TYPE_FULLTEXT:
+ case TRACKER_FIELD_TYPE_STRING:
+ rdf_type = "rdf:String";
+ break;
+ case TRACKER_FIELD_TYPE_INTEGER:
+ case TRACKER_FIELD_TYPE_DOUBLE:
+ case TRACKER_FIELD_TYPE_DATE:
+ rdf_type = "rdf:Integer";
+ break;
+ case TRACKER_FIELD_TYPE_BLOB:
+ case TRACKER_FIELD_TYPE_STRUCT:
+ case TRACKER_FIELD_TYPE_LINK:
+ g_warning ("Unsupport field type for property %s\n", tracker_field_get_name (field_def));
+ return NULL;
+ }
+
+ rdf_value = g_strdup_printf ("<%s>%s</%s>", rdf_type, value, rdf_type);
+
+ rdf_query = g_strconcat (CONDITION_OPEN, CLAUSE, rdf_value, CONDITION_CLOSE, NULL);
+
+ g_free (rdf_value);
+
+ return rdf_query;
+
+
+}
Modified: trunk/src/trackerd/tracker-rdf-query.h
==============================================================================
--- trunk/src/trackerd/tracker-rdf-query.h (original)
+++ trunk/src/trackerd/tracker-rdf-query.h Tue Nov 4 13:38:00 2008
@@ -50,6 +50,9 @@
gchar **where,
GError **error);
+gchar *tracker_rdf_query_for_attr_value (const gchar *field,
+ const gchar *value);
+
G_END_DECLS
#endif /* __TRACKERD_RDF_QUERY_H__ */
Modified: trunk/src/trackerd/tracker-search.c
==============================================================================
--- trunk/src/trackerd/tracker-search.c (original)
+++ trunk/src/trackerd/tracker-search.c Tue Nov 4 13:38:00 2008
@@ -47,6 +47,8 @@
#define DEFAULT_SEARCH_MAX_HITS 1024
#define SEARCH_KEEPALIVE_TIME_FOR_SQL_QUERY 600
+static GQuark error_quark;
+
typedef struct {
TrackerConfig *config;
TrackerLanguage *language;
@@ -894,6 +896,91 @@
tracker_dbus_request_success (request_id);
}
+static TrackerDBResultSet *
+perform_rdf_query (gint request_id,
+ const gchar *service,
+ gchar **fields,
+ const gchar *search_text,
+ const gchar *keyword,
+ const gchar *query_condition,
+ gboolean sort_by_service,
+ gchar **sort_fields,
+ gboolean sort_desc,
+ gint offset,
+ gint max_hits,
+ GError **error)
+{
+ static gboolean inited = FALSE;
+ TrackerDBInterface *iface;
+ TrackerDBResultSet *result_set;
+
+ if (!inited) {
+ error_quark = g_quark_from_static_string ("RDF-processing-error");
+ inited = TRUE;
+ }
+
+ result_set = NULL;
+
+ iface = tracker_db_manager_get_db_interface_by_service (service);
+
+ if (query_condition) {
+ GError *query_error = NULL;
+ gchar *query_translated;
+
+ tracker_dbus_request_comment (request_id,
+ "Executing RDF query:'%s' with search "
+ "term:'%s' and keyword:'%s'",
+ query_condition,
+ search_text,
+ keyword);
+
+ query_translated = tracker_rdf_query_to_sql (iface,
+ query_condition,
+ service,
+ fields,
+ g_strv_length (fields),
+ search_text,
+ keyword,
+ sort_by_service,
+ sort_fields,
+ (sort_fields ? g_strv_length (sort_fields) : 0),
+ sort_desc,
+ offset,
+ search_sanity_check_max_hits (max_hits),
+ &query_error);
+
+ if (query_error) {
+ g_propagate_error (error, query_error);
+ return NULL;
+ } else if (!query_translated) {
+ g_set_error (error, error_quark, 0, "Invalid rdf query, no error given");
+ return NULL;
+ }
+
+ tracker_dbus_request_comment (request_id,
+ "Translated RDF query:'%s'",
+ query_translated);
+
+ if (!tracker_is_empty_string (search_text)) {
+ tracker_db_search_text (iface,
+ service,
+ search_text,
+ 0,
+ 999999,
+ TRUE,
+ FALSE);
+ }
+
+ result_set = tracker_db_interface_execute_query (iface,
+ NULL,
+ query_translated);
+ g_free (query_translated);
+ }
+
+ return result_set;
+}
+
+
void
tracker_search_metadata (TrackerSearch *object,
const gchar *service,
@@ -905,7 +992,6 @@
GError **error)
{
GError *actual_error = NULL;
- TrackerDBInterface *iface;
TrackerDBResultSet *result_set;
guint request_id;
gchar **values;
@@ -929,32 +1015,34 @@
max_hits);
if (!tracker_ontology_service_is_valid (service)) {
- g_set_error (&actual_error,
- TRACKER_DBUS_ERROR,
- 0,
- "Service '%s' is invalid or has not been implemented yet",
- service);
+ tracker_dbus_request_failed (request_id,
+ &actual_error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
dbus_g_method_return_error (context, actual_error);
g_error_free (actual_error);
return;
}
- iface = tracker_db_manager_get_db_interface_by_service (service);
+ if (tracker_ontology_get_field_by_name (field) == NULL) {
+ tracker_dbus_request_failed (request_id,
+ &actual_error,
+ "Metadata field '%s' not registered in the system",
+ field);
+ dbus_g_method_return_error (context, actual_error);
+ g_error_free (actual_error);
+ return;
+ }
- /* FIXME: This function no longer exists, it was returning
- * NULL in every case, this DBus function needs rewriting or
- * to be removed.
- */
- result_set = NULL;
- /* result_set = tracker_db_search_metadata (iface, */
- /* service, */
- /* field, */
- /* text, */
- /* offset, */
- /* search_sanity_check_max_hits (max_hits)); */
+ gchar *fields[] = {"File:NameDelimited", NULL};
+ gchar *query_condition = tracker_rdf_query_for_attr_value (field, search_text);
+
+ result_set = perform_rdf_query (request_id, service, fields, "", "", query_condition,
+ FALSE, NULL, FALSE, offset, max_hits, &actual_error);
- values = tracker_dbus_query_result_to_strv (result_set, 0, NULL);
+ g_free (query_condition);
+ values = tracker_dbus_query_result_to_strv (result_set, 1, NULL);
dbus_g_method_return (context, values);
@@ -1041,6 +1129,7 @@
tracker_dbus_request_success (request_id);
}
+
void
tracker_search_query (TrackerSearch *object,
gint live_query_id,
@@ -1058,7 +1147,6 @@
GError **error)
{
GError *actual_error = NULL;
- TrackerDBInterface *iface;
TrackerDBResultSet *result_set;
guint request_id;
GPtrArray *values = NULL;
@@ -1096,70 +1184,17 @@
return;
}
- result_set = NULL;
-
- iface = tracker_db_manager_get_db_interface_by_service (service);
-
- if (query_condition) {
- GError *query_error = NULL;
- gchar *query_translated;
-
- tracker_dbus_request_comment (request_id,
- "Executing RDF query:'%s' with search "
- "term:'%s' and keyword:'%s'",
- query_condition,
- search_text,
- keyword);
-
- query_translated = tracker_rdf_query_to_sql (iface,
- query_condition,
- service,
- fields,
- g_strv_length (fields),
- search_text,
- keyword,
- sort_by_service,
- sort_fields,
- g_strv_length (sort_fields),
- sort_desc,
- offset,
- search_sanity_check_max_hits (max_hits),
- &query_error);
-
- if (query_error) {
- tracker_dbus_request_failed (request_id,
- &query_error,
- NULL);
- dbus_g_method_return_error (context, query_error);
- g_error_free (query_error);
- return;
- } else if (!query_translated) {
- tracker_dbus_request_failed (request_id,
- &actual_error,
- "Invalid rdf query, no error given");
- dbus_g_method_return_error (context, actual_error);
- g_error_free (actual_error);
- return;
- }
- tracker_dbus_request_comment (request_id,
- "Translated RDF query:'%s'",
- query_translated);
+ result_set = perform_rdf_query (request_id, service, fields, search_text, keyword, query_condition,
+ sort_by_service, sort_fields, sort_desc, offset, max_hits, &actual_error);
- if (!tracker_is_empty_string (search_text)) {
- tracker_db_search_text (iface,
- service,
- search_text,
- 0,
- 999999,
- TRUE,
- FALSE);
- }
-
- result_set = tracker_db_interface_execute_query (iface,
- NULL,
- query_translated);
- g_free (query_translated);
+ if (actual_error) {
+ tracker_dbus_request_failed (request_id,
+ &actual_error,
+ NULL);
+ dbus_g_method_return_error (context, actual_error);
+ g_error_free (actual_error);
+ return;
}
values = tracker_dbus_query_result_multi_to_ptr_array (result_set);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]