tracker r1770 - in branches/indexer-split: . data src/libtracker-db src/trackerd



Author: pvanhoof
Date: Thu Jun 26 10:57:59 2008
New Revision: 1770
URL: http://svn.gnome.org/viewvc/tracker?rev=1770&view=rev

Log:
2008-06-26  Philip Van Hoof  <pvanhoof gnome org>

        * svn merge -r 1726:1769 ../xesam-support



Modified:
   branches/indexer-split/ChangeLog
   branches/indexer-split/data/sqlite-stored-procs.sql
   branches/indexer-split/data/sqlite-xesam.sql
   branches/indexer-split/src/libtracker-db/tracker-db-manager.c
   branches/indexer-split/src/trackerd/tracker-db.c
   branches/indexer-split/src/trackerd/tracker-db.h
   branches/indexer-split/src/trackerd/tracker-xesam-query.c

Modified: branches/indexer-split/data/sqlite-stored-procs.sql
==============================================================================
--- branches/indexer-split/data/sqlite-stored-procs.sql	(original)
+++ branches/indexer-split/data/sqlite-stored-procs.sql	Thu Jun 26 10:57:59 2008
@@ -209,6 +209,13 @@
 GetXesamMetaDataChildren SELECT Child FROM XesamMetaDataChildren WHERE Parent = ?;
 GetXesamMetaDataMappings SELECT MetaName FROM XesamMetaDataMapping WHERE XesamMetaName = ?;
 GetXesamMetaDataLookups SELECT DISTINCT MetaName FROM XesamMetaDataLookup WHERE XesamMetaName = ?;
+GetXesamMetaDataTextLookups SELECT DISTINCT L.MetaName FROM XesamMetaDataLookup L INNER JOIN XesamMetaDataTypes T ON (T.MetaName = L.XesamMetaName) WHERE T.DataTypeID = 3;
 
 GetXesamMetaDataTypes SELECT ID, MetaName, DataTypeID, FieldName, Weight, Embedded, MultipleValues, Delimited, Filtered, Abstract FROM XesamMetaDataTypes;
 GetXesamServiceTypes SELECT TypeID, TypeName, Parents, Enabled, Embedded, HasMetadata, HasFullText, HasThumbs, ContentMetadata, Database, ShowServiceFiles, ShowServiceDirectories, KeyMetadata1, KeyMetadata2, KeyMetadata3, KeyMetadata4, KeyMetadata5, KeyMetadata6, KeyMetadata7, KeyMetadata8, KeyMetadata9, KeyMetadata10, KeyMetadata11  FROM XesamServiceTypes;
+
+InsertXesamMimes replace into XesamFileMimes (Mime) Values (?);
+InsertXesamMimePrefixes replace into XesamFileMimePrefixes (MimePrefix) Values (?);
+
+GetXesamMimeForServiceId select Mime from XesamFileMimes where ServiceTypeId = ?;
+GetXesamMimePrefixForServiceId select MimePrefix from XesamFileMimePrefixes where ServiceTypeId = ?;
\ No newline at end of file

Modified: branches/indexer-split/data/sqlite-xesam.sql
==============================================================================
--- branches/indexer-split/data/sqlite-xesam.sql	(original)
+++ branches/indexer-split/data/sqlite-xesam.sql	Thu Jun 26 10:57:59 2008
@@ -143,4 +143,24 @@
 	MetaName		Text,
 
 	unique (XesamMetaName, MetaName)
+);
+
+CREATE TABLE  XesamFileMimes
+(
+	Mime			Text primary key not null,
+	ServiceTypeID		Integer default 0,
+	ThumbExec		Text default ' ',
+	MetadataExec		Text default ' ',
+	FullTextExec		Text default ' '
+
+);
+
+CREATE TABLE  XesamFileMimePrefixes
+(
+	MimePrefix		Text primary key not null,
+	ServiceTypeID		Integer default 0,
+	ThumbExec		Text default ' ',
+	MetadataExec		Text default ' ',
+	FullTextExec		Text default ' '
+
 );
\ No newline at end of file

Modified: branches/indexer-split/src/libtracker-db/tracker-db-manager.c
==============================================================================
--- branches/indexer-split/src/libtracker-db/tracker-db-manager.c	(original)
+++ branches/indexer-split/src/libtracker-db/tracker-db-manager.c	Thu Jun 26 10:57:59 2008
@@ -610,14 +610,13 @@
 	GError               *error = NULL;
 	const gchar * const  *language_names;
 	gchar               **groups;
-	gchar               **group;
 	gchar 		     *service_file;
 	gchar                *sql;
 	gboolean              is_metadata;
 	gboolean              is_service;
 	gboolean              is_metadata_mapping;
 	gboolean              is_service_mapping;
-	gint                  id; 
+	gint                  i, j, id; 
 
 	const gchar          *data_types[] = {
 		"string", 
@@ -672,35 +671,34 @@
 		
 	groups = g_key_file_get_groups (key_file, NULL);
 	
-	for (group = groups; *group; group++) {
+	for (i = 0; groups[i]; i++) {
 		gchar  *str_id;
 		gchar **keys;
-		gchar **key;
 
 		if (is_metadata) {
 			db_exec_proc (iface, 
 				      "InsertXesamMetadataType", 
-				      *group, 
+				      groups[i], 
 				      NULL);
 			id = tracker_db_interface_sqlite_get_last_insert_id (TRACKER_DB_INTERFACE_SQLITE (iface));
 		} else if (is_service) {
 			db_exec_proc (iface, 
 				      "InsertXesamServiceType", 
-				      *group, 
+				      groups[i], 
 				      NULL);
 			id = tracker_db_interface_sqlite_get_last_insert_id (TRACKER_DB_INTERFACE_SQLITE (iface));
  		}
 		
 		/* Get inserted ID */
 		str_id = tracker_uint_to_string (id);
-		keys = g_key_file_get_keys (key_file, *group, NULL, NULL);
+		keys = g_key_file_get_keys (key_file, groups[i], NULL, NULL);
 		
-		for (key = keys; *key; key++) {
+		for (j = 0; keys[j]; j++) {
 			gchar *value;
 			
 			value = g_key_file_get_locale_string (key_file, 
-							      *group, 
-							      *key, 
+							      groups[i], 
+							      keys[j], 
 							      language_names[0],
 							      NULL);
 			
@@ -717,12 +715,12 @@
 			}
 			
 			if (is_metadata) {
-				if (strcasecmp (*key, "Parents") == 0) {
+				if (strcasecmp (keys[j], "Parents") == 0) {
 					load_service_file_xesam_insert (iface,
 									"INSERT INTO XesamMetadataChildren (Parent, Child) VALUES ('%s', '%s')",
 									value,
-									*group);
-				} else if (strcasecmp (*key, "ValueType") == 0) {
+									groups[i]);
+				} else if (strcasecmp (keys[j], "ValueType") == 0) {
 					gint data_id;
 					
 					data_id = tracker_string_in_string_list (value, (gchar **) data_types);
@@ -774,20 +772,67 @@
 				} else {
 					load_service_file_xesam_update (iface,
 									"update XesamMetadataTypes set  %s = '%s' where ID = %s",
-									*key, 
+									keys[j], 
 									value, 
 									str_id);
 				}
 			} else 	if (is_service) {
-				if (strcasecmp (*key, "Parents") == 0) {
+				if (strcasecmp (keys[j], "Parents") == 0) {
 					load_service_file_xesam_insert (iface,
 									"INSERT INTO XesamServiceChildren (Parent, Child) VALUES ('%s', '%s')",
 									value,
-									*group);
+									groups[i]);
+				} else if (strcasecmp (keys[j], "Mimes") == 0) {
+					gchar **tab_array;
+					gint    k;
+					
+					tab_array = g_key_file_get_string_list (key_file, 
+										groups[i], 
+										keys[j], 
+										NULL, 
+										NULL);
+					
+					for (k = 0; tab_array[k]; k++) {
+						tracker_db_interface_execute_procedure (iface, NULL,
+											"InsertXesamMimes",
+											tab_array[k], 
+											NULL);
+						tracker_db_interface_execute_query (iface, 
+										    NULL,
+										    "update XesamFileMimes set ServiceTypeID = %s where Mime = '%s'",
+										    str_id, 
+										    tab_array[k]);
+					}
+					
+					g_strfreev (tab_array);
+				} else if (strcasecmp (keys[j], "MimePrefixes") == 0) {
+					gchar **tab_array;
+					gint    k;
+					
+					tab_array = g_key_file_get_string_list (key_file, 
+										groups[i], 
+										keys[j], 
+										NULL, 
+										NULL);
+					
+					for (k = 0; tab_array[k]; k++) {
+						tracker_db_interface_execute_procedure (iface, 
+											NULL,
+											"InsertXesamMimePrefixes",
+											tab_array[k],
+											NULL);
+						tracker_db_interface_execute_query (iface, 
+										    NULL,
+										    "update XesamFileMimePrefixes set ServiceTypeID = %s where MimePrefix = '%s'",
+										    str_id, 
+										    tab_array[k]);
+					}
+					
+					g_strfreev (tab_array);
 				} else {
 					load_service_file_xesam_update (iface,
 									"update XesamServiceTypes set  %s = '%s' where typeID = %s",
-									*key, 
+									keys[j], 
 									value, 
 									str_id);
 				}
@@ -795,12 +840,12 @@
 				load_service_file_xesam_map (iface,
 							     "InsertXesamMetaDataMapping", 
 							     value, 
-							     *group);
+							     groups[i]);
 			} else {
 				load_service_file_xesam_map (iface,
 							     "InsertXesamServiceMapping", 
 							     value, 
-							     *group);
+							     groups[i]);
 			}
 			
 			g_free (value);
@@ -1064,6 +1109,20 @@
 	return db_mime_query (iface, "GetMimePrefixForServiceId", service_id);
 }
 
+static GSList *
+db_get_xesam_mimes_for_service_id (TrackerDBInterface *iface,
+				   gint                service_id)
+{
+	return db_mime_query (iface, "GetXesamMimeForServiceId", service_id);
+}
+
+static GSList *
+db_get_xesam_mime_prefixes_for_service_id (TrackerDBInterface *iface,
+					   gint                service_id)
+{
+	return db_mime_query (iface, "GetXesamMimePrefixForServiceId", service_id);
+}
+
 /* Sqlite utf-8 user defined collation sequence */
 static gint
 utf8_collation_func (gchar *str1,
@@ -1627,8 +1686,8 @@
                         id = tracker_service_get_id (service);
                         name = tracker_service_get_name (service);
 
-                        mimes = db_get_mimes_for_service_id (iface, id);
-                        mime_prefixes = db_get_mime_prefixes_for_service_id (iface, id);
+                        mimes = db_get_xesam_mimes_for_service_id (iface, id);
+                        mime_prefixes = db_get_xesam_mime_prefixes_for_service_id (iface, id);
 
                         g_message ("Adding xesam service:'%s' with id:%d and mimes:%d",
 				   name,
@@ -2104,7 +2163,7 @@
 
 
 	/* Load static xesam data */
-	db_get_static_xesam_data (attach_iface);
+	db_get_static_xesam_data (iface);
 
 	return iface;
 }

Modified: branches/indexer-split/src/trackerd/tracker-db.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-db.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-db.c	Thu Jun 26 10:57:59 2008
@@ -1389,6 +1389,20 @@
 }
 
 TrackerDBResultSet *
+tracker_db_xesam_get_all_text_metadata_names (TrackerDBInterface *iface)
+{
+	TrackerDBResultSet *result_set;
+
+	g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+	
+	result_set = tracker_db_exec_proc (iface,
+					   "GetXesamMetaDataTextLookups", 
+					   NULL);
+
+	return result_set;
+}
+
+TrackerDBResultSet *
 tracker_db_xesam_get_service_names (TrackerDBInterface *iface, 
 				    const gchar        *name)
 {
@@ -2542,9 +2556,9 @@
  * It is used by xesam_live_search parsing. */
 
 static GList *
-add_metadata_field (TrackerDBInterface *iface,
-		    GSList **fields, 
-		    const char *xesam_name)
+add_live_search_metadata_field (TrackerDBInterface *iface,
+				GSList **fields, 
+				const char *xesam_name)
 {
 	TrackerDBResultSet *result_set;
 	TrackerFieldData   *field_data;
@@ -2636,9 +2650,9 @@
 	while (field_names[i]) {
 		GList *field_data_list = NULL;
 
-		field_data_list = add_metadata_field (iface, 
-						      &fields, 
-						      field_names[i]);
+		field_data_list = add_live_search_metadata_field (iface, 
+								  &fields, 
+								  field_names[i]);
 
 		if (!field_data_list) {
 			g_warning ("Asking for a non-mapped xesam field: %s", field_names[i]);

Modified: branches/indexer-split/src/trackerd/tracker-db.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-db.h	(original)
+++ branches/indexer-split/src/trackerd/tracker-db.h	Thu Jun 26 10:57:59 2008
@@ -231,12 +231,12 @@
 								  const gchar         *search_id);
 
 /* XESAM API */
-void                tracker_db_xesam_delete_handled_events       (TrackerDBInterface  *iface);
-TrackerDBResultSet *tracker_db_xesam_get_metadata_names          (TrackerDBInterface  *iface,
-								  const char          *name);
-TrackerDBResultSet *tracker_db_xesam_get_service_names           (TrackerDBInterface  *iface,
-								  const char          *name);
-
+void                tracker_db_xesam_delete_handled_events     (TrackerDBInterface  *iface);
+TrackerDBResultSet *tracker_db_xesam_get_metadata_names        (TrackerDBInterface  *iface,
+								const char          *name);
+TrackerDBResultSet *tracker_db_xesam_get_all_text_metadata_names (TrackerDBInterface  *iface);
+TrackerDBResultSet *tracker_db_xesam_get_service_names         (TrackerDBInterface  *iface,
+								const char          *name);
 G_END_DECLS
 
 #endif /* __TRACKERD_DB_H__ */

Modified: branches/indexer-split/src/trackerd/tracker-xesam-query.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-xesam-query.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-xesam-query.c	Thu Jun 26 10:57:59 2008
@@ -21,6 +21,25 @@
  * Boston, MA  02110-1301, USA.
  */
 
+/*
+ * TODO
+ * - Boost attribute support is missing completely
+ * - userQuery is missing completely
+ * - works only with the default db at the moment.
+ * - Missing checks for several field elements in one selector
+ *
+ *
+ *
+ *
+ * FIXME
+ * - The mappings
+ * - Multifield-elements work in a hackish way with a magic current_field name. An additional field is pushed to stack for fullText.
+ */
+
+
+#define FIELD_NAME_FULL_TEXT_FIELDS "fullTextFields"
+
+
 #include <string.h>
 
 #include <libtracker-common/tracker-log.h>
@@ -50,6 +69,7 @@
 #define ELEMENT_XESAM_QUERY 	        "query"
 #define ELEMENT_XESAM_USER_QUERY        "userQuery"
 #define ELEMENT_XESAM_FIELD 		"field"
+#define ELEMENT_XESAM_FULL_TEXT_FIELDS  "fullTextFields"
 #define ELEMENT_XESAM_REQUEST 		"request"
 
 /* Operators */
@@ -68,6 +88,7 @@
 #define ELEMENT_XESAM_REGEX        	"regex"
 #define ELEMENT_XESAM_STARTS_WITH 	"startsWith"
 #define ELEMENT_XESAM_IN_SET		"inSet"
+#define ELEMENT_XESAM_FULL_TEXT         "fullText"
 
 /* Types */
 #define ELEMENT_XESAM_INTEGER 		"integer"
@@ -112,6 +133,8 @@
 	STATE_END_STARTS_WITH,
 	STATE_IN_SET,
 	STATE_END_IN_SET,
+	STATE_FULL_TEXT,
+	STATE_END_FULL_TEXT,
 	STATE_INTEGER,
 	STATE_END_INTEGER,
 	STATE_STRING,
@@ -135,6 +158,7 @@
 	OP_CONTAINS,
 	OP_REGEX,
 	OP_SET,
+	OP_FULL_TEXT,
 	OP_STARTS
 } Operators;
 
@@ -194,6 +218,7 @@
 		state == STATE_LESS_THAN ||
 		state == STATE_CONTAINS || 
 		state == STATE_IN_SET || 
+		state == STATE_FULL_TEXT ||
 		state == STATE_LESS_OR_EQUAL ||
 		state == STATE_GREATER_OR_EQUAL || 
 		state == STATE_STARTS_WITH || 
@@ -209,7 +234,8 @@
 		state == STATE_END_GREATER_THAN || 
 		state == STATE_END_LESS_THAN ||
 		state == STATE_END_CONTAINS || 
-		state == STATE_END_IN_SET || 
+		state == STATE_END_IN_SET ||
+		state == STATE_END_FULL_TEXT ||
 		state == STATE_END_LESS_OR_EQUAL ||
 		state == STATE_END_GREATER_OR_EQUAL || 
 		state == STATE_END_STARTS_WITH || 
@@ -369,8 +395,12 @@
 	valid = TRUE;
 
 	/* Do the xesam mapping */
-	
-	result_set = tracker_db_xesam_get_metadata_names (data->iface, xesam_name);
+	if (!strcmp(xesam_name,FIELD_NAME_FULL_TEXT_FIELDS)) {
+		result_set = tracker_db_xesam_get_all_text_metadata_names (data->iface);
+	} else {	
+		result_set = tracker_db_xesam_get_metadata_names (data->iface, xesam_name);
+	}
+
 	if (!result_set) {
 		return NULL;
 	}
@@ -390,16 +420,15 @@
 				continue;
 			}
 				
-			if (strcasecmp (this_field_name, field_name) != 0) {
-				continue;
+			if (strcasecmp (this_field_name, field_name) == 0) {
+				field_data = l->data;
+				field_exists = TRUE;
+				
+				tracker_field_data_set_is_condition (l->data, is_condition);
+				tracker_field_data_set_is_select (l->data, is_select);
+				
+				break;
 			}
-
-			field_exists = TRUE;
-			
-			tracker_field_data_set_is_condition (l->data, is_condition);
-			tracker_field_data_set_is_select (l->data, is_select);
-			
-			break;
 		}
 		
 		if (!field_exists) {
@@ -414,7 +443,10 @@
 			} 
 		} 
 		
-		reply = g_list_append (reply, field_data);
+		if (field_data) {
+			reply = g_list_append (reply, field_data);
+		}
+
 		valid = tracker_db_result_set_iter_next (result_set);
 		g_free (field_name);
 	}
@@ -516,6 +548,26 @@
 			data->current_field = g_strdup (name);
 			push_stack (data, STATE_FIELD);
 		}
+	} else if (ELEMENT_IS (ELEMENT_XESAM_FULL_TEXT_FIELDS)) {
+
+		if (set_error_on_fail (is_operator (state), 
+				       context, 
+				       "Field element (fullTextFields) not expected here", 
+				       error)) {
+			return;
+		}
+		
+		if (data->current_operator == OP_NONE) {
+			set_error (error, 
+				   context, 
+				   PARSE_ERROR,
+				   "no operator found for fullTextFields");
+			return;
+		}
+		
+		data->current_field = g_strdup (FIELD_NAME_FULL_TEXT_FIELDS);
+		push_stack (data, STATE_FIELD); /* We don't need to differentiate */
+	
 	} else if (ELEMENT_IS (ELEMENT_XESAM_AND)) {
                 const gchar *negate;
 
@@ -800,8 +852,33 @@
 
 		data->current_operator = OP_SET;
 		push_stack (data, STATE_IN_SET);
+	} else if (ELEMENT_IS (ELEMENT_XESAM_FULL_TEXT)) {
+                const gchar *negate;
+
+		if (set_error_on_fail (state == STATE_QUERY || 
+				       is_logic (state) ||
+				       ((data->current_logic_operator == LOP_AND || 
+					 data->current_logic_operator == LOP_OR) &&
+					is_end_operator (state)),
+				       context, 
+				       "fullText element not expected here", 
+				       error)) {
+			return;
+		}
+
+		negate = get_attribute_value ("negate", 
+					      attribute_names, 
+					      attribute_values);
+
+		if (negate && !strcmp(negate,"true")) {
+			data->sql_where = g_string_append (data->sql_where, " NOT "); 
+		}
+
+		data->current_operator = OP_FULL_TEXT;
+		data->current_field = g_strdup (FIELD_NAME_FULL_TEXT_FIELDS);
+		push_stack (data, STATE_FULL_TEXT);
 	} else if (ELEMENT_IS (ELEMENT_XESAM_INTEGER)) {
-		if (set_error_on_fail (state == STATE_FIELD, 
+		if (set_error_on_fail (state == STATE_FIELD || state == STATE_FULL_TEXT, 
 				       context, 
 				       "INTEGER element not expected here", 
 				       error)) {
@@ -810,7 +887,7 @@
 
 		push_stack (data, STATE_INTEGER);
 	} else if (ELEMENT_IS (ELEMENT_XESAM_DATE)) {
-		if (set_error_on_fail (state == STATE_FIELD, 
+		if (set_error_on_fail (state == STATE_FIELD || state == STATE_FULL_TEXT, 
 				       context,
 				       "DATE element not expected here", 
 				       error)) {
@@ -819,7 +896,7 @@
 
 		push_stack (data, STATE_DATE);
 	} else if (ELEMENT_IS (ELEMENT_XESAM_STRING)) {
-		if (set_error_on_fail (state == STATE_FIELD, 
+		if (set_error_on_fail (state == STATE_FIELD || state == STATE_FULL_TEXT, 
 				       context,
 				       "STRING element not expected here", 
 				       error)) {
@@ -828,7 +905,7 @@
 
 		push_stack (data, STATE_STRING);
 	} else if (ELEMENT_IS (ELEMENT_XESAM_FLOAT)) {
-		if (set_error_on_fail (state == STATE_FIELD, 
+		if (set_error_on_fail (state == STATE_FIELD || state == STATE_FULL_TEXT, 
 				       context, 
 				       "FLOAT element not expected here", 
 				       error)) {
@@ -837,7 +914,7 @@
 
 		push_stack (data, STATE_FLOAT);
 	} else if (ELEMENT_IS (ELEMENT_XESAM_BOOLEAN)) {
-		if (set_error_on_fail (state == STATE_FIELD, 
+		if (set_error_on_fail (state == STATE_FIELD || state == STATE_FULL_TEXT, 
 				       context, 
 				       "BOOLEAN element not expected here", 
 				       error)) {
@@ -1061,6 +1138,21 @@
 			}
 			break;
 
+		case OP_FULL_TEXT:
+
+			sub = strchr (data->current_value, '*');
+
+			if (sub) {
+				g_string_append_printf (str, " (%s like '%%%s%%') ", 
+							where_field, 
+							data->current_value);
+			} else {
+				g_string_append_printf (str, " (%s like '%%%s%%') ", 
+							where_field,
+							data->current_value);
+			}
+			break;
+
 		default:
 			break;
 		}
@@ -1209,6 +1301,14 @@
 
 		push_stack (data, STATE_END_IN_SET);
 
+	} else if (ELEMENT_IS (ELEMENT_XESAM_FULL_TEXT)) {
+
+		if (!build_sql (data)) {
+			set_error (error, context, 1, "parse error");
+			return;
+		}
+
+		push_stack (data, STATE_END_FULL_TEXT);
 
 	} else if (ELEMENT_IS (ELEMENT_XESAM_INTEGER)) {
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]