tracker r2480 - in branches/libtracker-data: . src/libtracker-data src/trackerd
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2480 - in branches/libtracker-data: . src/libtracker-data src/trackerd
- Date: Mon, 10 Nov 2008 10:33:15 +0000 (UTC)
Author: juergbi
Date: Mon Nov 10 10:33:15 2008
New Revision: 2480
URL: http://svn.gnome.org/viewvc/tracker?rev=2480&view=rev
Log:
2008-11-10 JÃrg Billeter <j bitron ch>
* src/libtracker-data/tracker-data-search.c:
* src/libtracker-data/tracker-data-search.h:
* src/trackerd/tracker-keywords.c:
Move SQL query from trackerd/tracker-keywords to
libtracker-data/tracker-data-search
Modified:
branches/libtracker-data/ChangeLog
branches/libtracker-data/src/libtracker-data/tracker-data-search.c
branches/libtracker-data/src/libtracker-data/tracker-data-search.h
branches/libtracker-data/src/trackerd/tracker-keywords.c
Modified: branches/libtracker-data/src/libtracker-data/tracker-data-search.c
==============================================================================
--- branches/libtracker-data/src/libtracker-data/tracker-data-search.c (original)
+++ branches/libtracker-data/src/libtracker-data/tracker-data-search.c Mon Nov 10 10:33:15 2008
@@ -1484,3 +1484,86 @@
return result_set;
}
+TrackerDBResultSet *
+tracker_data_search_keywords (const gchar *service_type,
+ const gchar **keywords,
+ gint offset,
+ gint max_hits,
+ GError **error)
+{
+ TrackerDBInterface *iface;
+ TrackerDBResultSet *result_set;
+ const gchar **p;
+ GString *search;
+ GString *select;
+ GString *where;
+ gchar *related_metadata;
+ gchar *query;
+
+ g_return_val_if_fail (service_type != NULL, NULL);
+ g_return_val_if_fail (keywords != NULL, NULL);
+
+ if (!tracker_ontology_service_is_valid (service_type)) {
+ g_set_error (error, TRACKER_DBUS_ERROR, 0,
+ "Service_Type '%s' is invalid or has not been implemented yet",
+ service_type);
+ return NULL;
+ }
+
+ iface = tracker_db_manager_get_db_interface_by_service (service_type);
+
+ /* Sanity check values */
+ offset = MAX (offset, 0);
+
+ /* Create keyword search string */
+ search = g_string_new ("");
+ g_string_append_printf (search,
+ "'%s'",
+ keywords[0]);
+
+ for (p = keywords + 1; *p; p++) {
+ g_string_append_printf (search, ", '%s'", *p);
+ }
+
+ /* Create select string */
+ select = g_string_new (" Select distinct S.Path || '");
+ select = g_string_append (select, G_DIR_SEPARATOR_S);
+ select = g_string_append (select,
+ "' || S.Name as EntityName from Services S, ServiceKeywordMetaData M ");
+
+ /* Create where string */
+ related_metadata = tracker_data_schema_metadata_field_get_related_names (iface, "User:Keywords");
+
+ where = g_string_new ("");
+ g_string_append_printf (where,
+ " where S.ID = M.ServiceID and M.MetaDataID in (%s) and M.MetaDataValue in (%s) ",
+ related_metadata,
+ search->str);
+ g_free (related_metadata);
+ g_string_free (search, TRUE);
+
+ g_string_append_printf (where,
+ " and (S.ServiceTypeID in (select TypeId from ServiceTypes where TypeName = '%s' or Parent = '%s')) ",
+ service_type,
+ service_type);
+
+ /* Add offset and max_hits */
+ g_string_append_printf (where,
+ " Limit %d,%d",
+ offset,
+ max_hits);
+
+ /* Finalize query */
+ query = g_strconcat (select->str, where->str, NULL);
+ g_string_free (select, TRUE);
+ g_string_free (where, TRUE);
+
+ g_debug (query);
+
+ result_set = tracker_db_interface_execute_query (iface, NULL, query);
+
+ g_free (query);
+
+ return result_set;
+}
+
Modified: branches/libtracker-data/src/libtracker-data/tracker-data-search.h
==============================================================================
--- branches/libtracker-data/src/libtracker-data/tracker-data-search.h (original)
+++ branches/libtracker-data/src/libtracker-data/tracker-data-search.h Mon Nov 10 10:33:15 2008
@@ -113,6 +113,12 @@
gchar **fields,
GError **error);
+TrackerDBResultSet *tracker_data_search_keywords (const gchar *service_type,
+ const gchar **keywords,
+ gint offset,
+ gint max_hits,
+ GError **error);
+
G_END_DECLS
#endif /* __TRACKER_DATA_SEARCH_H__ */
Modified: branches/libtracker-data/src/trackerd/tracker-keywords.c
==============================================================================
--- branches/libtracker-data/src/trackerd/tracker-keywords.c (original)
+++ branches/libtracker-data/src/trackerd/tracker-keywords.c Mon Nov 10 10:33:15 2008
@@ -500,15 +500,8 @@
DBusGMethodInvocation *context,
GError **error)
{
- TrackerDBInterface *iface;
TrackerDBResultSet *result_set;
guint request_id;
- const gchar **p;
- GString *search;
- GString *select;
- GString *where;
- gchar *related_metadata;
- gchar *query;
gchar **values;
GError *actual_error = NULL;
@@ -526,79 +519,23 @@
offset,
max_hits);
- if (!tracker_ontology_service_is_valid (service_type)) {
- tracker_dbus_request_failed (request_id,
- &actual_error,
- "Service_Type '%s' is invalid or has not been implemented yet",
- service_type);
- dbus_g_method_return_error (context, actual_error);
- g_error_free (actual_error);
- return;
- }
-
- iface = tracker_db_manager_get_db_interface_by_service (service_type);
-
- /* Sanity check values */
- offset = MAX (offset, 0);
-
- /* Create keyword search string */
- search = g_string_new ("");
- g_string_append_printf (search,
- "'%s'",
- keywords[0]);
+ result_set = tracker_data_search_keywords (service_type,
+ keywords,
+ offset,
+ max_hits,
+ &actual_error);
- for (p = keywords + 1; *p; p++) {
- g_string_append_printf (search, ", '%s'", *p);
+ if (actual_error) {
+ g_propagate_error (error, actual_error);
+ return;
}
- tracker_dbus_request_comment (request_id,
- "Executing keyword search on %s",
- search->str);
-
- /* Create select string */
- select = g_string_new (" Select distinct S.Path || '");
- select = g_string_append (select, G_DIR_SEPARATOR_S);
- select = g_string_append (select,
- "' || S.Name as EntityName from Services S, ServiceKeywordMetaData M ");
-
- /* Create where string */
- related_metadata = tracker_data_schema_metadata_field_get_related_names (iface, "User:Keywords");
-
- where = g_string_new ("");
- g_string_append_printf (where,
- " where S.ID = M.ServiceID and M.MetaDataID in (%s) and M.MetaDataValue in (%s) ",
- related_metadata,
- search->str);
- g_free (related_metadata);
- g_string_free (search, TRUE);
-
- g_string_append_printf (where,
- " and (S.ServiceTypeID in (select TypeId from ServiceTypes where TypeName = '%s' or Parent = '%s')) ",
- service_type,
- service_type);
-
- /* Add offset and max_hits */
- g_string_append_printf (where,
- " Limit %d,%d",
- offset,
- max_hits);
-
- /* Finalize query */
- query = g_strconcat (select->str, where->str, NULL);
- g_string_free (select, TRUE);
- g_string_free (where, TRUE);
-
- g_debug (query);
-
- result_set = tracker_db_interface_execute_query (iface, NULL, query);
values = tracker_dbus_query_result_to_strv (result_set, 0, NULL);
if (result_set) {
g_object_unref (result_set);
}
- g_free (query);
-
dbus_g_method_return (context, values);
if (values) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]