Index: tracker-dbus-search.c =================================================================== --- tracker-dbus-search.c (revision 553) +++ tracker-dbus-search.c (working copy) @@ -665,10 +665,10 @@ { DBConnection *db_con; DBusError dbus_error; - char **fields; - int limit, row_count, query_id, offset; + char **fields, **keywords; + int limit, field_count, keyword_count, query_id, offset; char ***res; - char *query, *search_text, *service, *keyword; + char *query, *search_text, *service; gboolean sort_results; g_return_if_fail (rec && rec->user_data); @@ -681,7 +681,7 @@ The service parameter specifies the service which the query will be performed on The fields parameter specifies an array of aditional metadata fields to return in addition to the id field (which is returned as the "key" in the resultant dict/hashtable) and the service category. This can be null The optional search_text paramter specifies the text to search for in a full text search of all indexed fields - this parameter can be null if the query_condition is not null (in which case only the query condition is used to find matches) - The optional keyword search - a single keyword may be used here to filter the results. + The optional keywords search - keywords used to filter the results. The optional query_condition parameter specifies an xml-based rdf query condition which is used to filter out the results - this parameter can be null if the search_text is not null (in which case only the search_text parameter is used to find matches) The Offset parameter sets the start row of the returned result set (useful for paging/cursors). A value of 0 should be passed to get rows from the beginning. The max_hits parameter limits the size of the result set. @@ -694,7 +694,7 @@ - + @@ -706,9 +706,9 @@ if (!dbus_message_get_args (rec->message, NULL, DBUS_TYPE_INT32, &query_id, DBUS_TYPE_STRING, &service, - DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &fields, &row_count, + DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &fields, &field_count, DBUS_TYPE_STRING, &search_text, - DBUS_TYPE_STRING, &keyword, + DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &keywords, &keyword_count, DBUS_TYPE_STRING, &query, DBUS_TYPE_BOOLEAN, &sort_results, DBUS_TYPE_INT32, &offset, @@ -734,9 +734,10 @@ char *str; GError *error = NULL; - tracker_log ("executing rdf query %s\n with search term %s and keyword %s", query, search_text, keyword); + tracker_log ("executing rdf query %s\n with search term %s", query, search_text); - str = tracker_rdf_query_to_sql (db_con, query, service, fields, row_count, search_text, keyword, sort_results, offset, limit, error); + str = tracker_rdf_query_to_sql (db_con, query, service, fields, field_count, search_text, + keywords, keyword_count, sort_results, offset, limit, error); if (error) { tracker_set_error (rec, "Invalid rdf query produced following error: %s", error->message); Index: tracker-rdf-query.c =================================================================== --- tracker-rdf-query.c (revision 553) +++ tracker-rdf-query.c (working copy) @@ -1137,7 +1137,7 @@ char * -tracker_rdf_query_to_sql (DBConnection *db_con, const char *query, const char *service, char **fields, int field_count, const char *search_text, const char *keyword, gboolean sort_by_service, int offset, int limit, GError *error) +tracker_rdf_query_to_sql (DBConnection *db_con, const char *query, const char *service, char **fields, int field_count, const char *search_text, char **keywords, int keyword_count, gboolean sort_by_service, int offset, int limit, GError *error) { static gboolean inited = FALSE; ParserData data; @@ -1176,10 +1176,12 @@ char *table_name; gboolean do_search = FALSE; + GString *keywords_restrictions; table_name = "Services"; data.sql_from = g_string_new (""); + keywords_restrictions = g_string_new (""); g_debug ("search term is %s", search_text); @@ -1191,11 +1193,32 @@ g_string_append_printf (data.sql_from, "\n FROM %s S ", table_name); } - if (keyword && strlen (keyword) > 0) { + if (keyword_count > 0) { + int i; + char *keyword_metadata = tracker_get_related_metadata_names (db_con, "DC:Keywords"); - g_string_append_printf (data.sql_from, "\n INNER JOIN ServiceKeywordMetaData K ON S.ID = K.ServiceID and K.MetaDataID in (%s) and K.MetaDataValue = '%s' ", keyword_metadata, keyword); + + for (i = 0; i < keyword_count; i++) { + if (i == 0) + g_string_append_printf(keywords_restrictions, "'%s'", keywords[i]); + else + g_string_append_printf(keywords_restrictions, ", '%s'", keywords[i]); + } + + for (i = 0; i < keyword_count; i++) { + g_string_append_printf (data.sql_from, "\n INNER JOIN ServiceKeywordMetaData K%d ON S.ID = K%d.ServiceID and K%d.MetaDataID in (%s) and K%d.MetaDataValue in (%s)", i, i, i, keyword_metadata, i, keywords_restrictions->str); + } + + g_string_free (keywords_restrictions, TRUE); + + keywords_restrictions = g_string_new (""); + + for (i = 0; i < keyword_count; i++) { + g_string_append_printf (keywords_restrictions, " AND K%d.MetaDataValue = '%s'", i, keywords[i]); + } + g_free (keyword_metadata); - } + } data.sql_where = g_string_new (""); @@ -1205,6 +1228,10 @@ g_string_append_printf (data.sql_where, "\n WHERE (S.ServiceTypeID between GetServiceTypeID('%s') and GetMaxServiceTypeID('%s')) AND ", service, service); } + g_string_append(data.sql_where, keywords_restrictions->str); + + g_string_free (keywords_restrictions, TRUE); + if (limit < 1) { limit = 1024; } @@ -1294,3 +1321,4 @@ } + Index: tracker-rdf-query.h =================================================================== --- tracker-rdf-query.h (revision 553) +++ tracker-rdf-query.h (working copy) @@ -27,6 +27,6 @@ #include "tracker-db.h" -char * tracker_rdf_query_to_sql (DBConnection *db_con, const char *query, const char *service, char **fields, int field_count, const char *search_text, const char *keyword, gboolean sort_by_service, int offset, int limit, GError *error); +char * tracker_rdf_query_to_sql (DBConnection *db_con, const char *query, const char *service, char **fields, int field_count, const char *search_text, char **keywords, int keyword_count, gboolean sort_by_service, int offset, int limit, GError *error); #endif