Here's a patch for tracker-search-tool that allows the user to
explicitly search certain metadata keys, ala Google.

For example, searching for "album:Global" will just search for
Audio:Album tags, instead of everything, for 'Global'. Currently, the
seach is case sensitive (any way to make rdf seraches
case-insensitive?).

This patch includes support for key:
 title  -->  DC:Title  (this isn't working for Audio:Title)
 format  -->  DC:Format
 creator  -->  DC:Creator
 keywords  -->  DC:Keywords
 mime  -->  File:Mime  (this isn't working, while `format` does)
 path  -->  File:Path
 ext  -->  File:Ext
 artist  -->  Audio:Artist
 album  -->  Audio:Album
 track  -->  Audio:Title
 subject  -->  Doc:Subject
 author  -->  Doc:Author
Index: src/tracker-search-tool/tracker-search-tool.c
===================================================================
--- src/tracker-search-tool/tracker-search-tool.c	(revision 394)
+++ src/tracker-search-tool/tracker-search-tool.c	(working copy)
@@ -2004,11 +2004,74 @@
 }
 
 void
+get_rdf_data (gchar **commands, gchar **rdf_rv)
+{
+	static struct {
+		gchar *key, *metaname;
+	} *p, map[] = {
+		{ "title",    "DC:Title" },
+		{ "format",   "DC:Format" },
+		{ "creator",  "DC:Creator" },
+		{ "keywords", "DC:Keywords" },
+		{ "mime",     "File:Mime" },
+		{ "path",     "File:Path" },
+		{ "ext",      "File:Ext" },
+		{ "artist",   "Audio:Artist" },
+		{ "album",    "Audio:Album" },
+		{ "track",    "Audio:Title" },
+		{ "subject",  "Doc:Subject" },
+		{ "author",   "Doc:Author" },
+		{ NULL,       NULL }
+	};
+	GString *rdf, *new_commands;
+	gboolean got_something = FALSE;
+	gchar  **command_tokens, **tok;
+	gchar  **item;
+
+	rdf = g_string_new ("<rdfq:Condition><rdfq:and>");
+	new_commands = g_string_new (NULL);
+
+	command_tokens = g_strsplit (*commands, " ", -1);
+	for (tok = command_tokens; *tok; ++tok) {
+		item = g_strsplit (*tok, ":", 2);
+		if (item[1] == NULL) {
+			g_string_append (new_commands, *tok);
+		}
+		else {
+			for (p = map; p->key; ++p) {
+				if (item[0] && strcmp (item[0], p->key) == 0) {
+					got_something = TRUE;
+					g_string_append_printf (rdf,
+						"<rdfq:contains>"
+						" <rdfq:Property name=\"%s\" />"
+						" <rdf:String>%s</rdf:String>"
+						"</rdfq:contains>",
+						p->metaname, item[1]);
+				}
+			}
+		}
+		g_strfreev (item);
+	}
+	g_strfreev (command_tokens);
+
+	g_free (*commands);
+	*commands = g_string_free (new_commands, FALSE);
+	if (got_something) {
+		g_string_append (rdf, "</rdfq:and></rdfq:Condition>");
+		*rdf_rv = g_string_free (rdf, FALSE);
+	}
+	else {
+		g_string_free (rdf, TRUE);
+	}
+}
+
+void
 click_find_cb (GtkWidget * widget,
                gpointer data)
 {
 	GSearchWindow * gsearch = data;
 	gchar * command;
+	gchar * rdf = NULL;
 	GPtrArray *out_array = NULL;
 	GtkTreeIter iter;
 	int type;
@@ -2038,8 +2101,18 @@
 			type = SERVICE_FILES;
 		}
 		
-   		
-		out_array = tracker_search_text_detailed (tracker_client, -1, type, command, gsearch->offset, MAX_SEARCH_RESULTS, NULL);
+		get_rdf_data (&command, &rdf);
+		command = g_strstrip (command);
+		if (rdf) {
+			gchar *fields[2] = { "File:Mime", NULL };
+			out_array = tracker_search_query (tracker_client, -1, type, fields, command, NULL, rdf, gsearch->offset, MAX_SEARCH_RESULTS, FALSE, NULL);
+
+			g_free (rdf);
+		}
+		else {
+			out_array = tracker_search_text_detailed (tracker_client, -1, type, command, gsearch->offset, MAX_SEARCH_RESULTS, NULL);
+		}
+
 		gsearch->is_locate_database_check_finished = TRUE;
 		stop_animation (gsearch);
 		g_free (command);
_______________________________________________
tracker-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/tracker-list

Reply via email to