Commit 75b8abbf authored by John Ralls's avatar John Ralls

[GtkSearchEngineQuartz] Limit the scope of the Spotlight search.

If the query has a non-null location, set the scope to that directory,
otherwise set it to the local computer.

There is unfortunately no way to get Spotlight to search
non-recursively, nor does NSFileManager offer a convenient search of
the contents of a directory's regular files.
parent 0f5603e7
......@@ -192,6 +192,8 @@ gtk_search_engine_quartz_set_query (GtkSearchEngine *engine,
GtkQuery *query)
GtkSearchEngineQuartz *quartz;
const char* path = NULL;
GFile *location = NULL;
......@@ -204,11 +206,28 @@ gtk_search_engine_quartz_set_query (GtkSearchEngine *engine,
g_object_unref (quartz->priv->query);
quartz->priv->query = query;
location = gtk_query_get_location (query);
if (location)
path = g_file_peek_path (location);
/* We create a query to look for ".*text.*" in the text contents of
* all indexed files. (Should we also search for text in file and folder
* names?).
if (path)
NSString *ns_path = [[NSString string] initWithUTF8String:path];
[quartz->priv->ns_query setSearchScopes:@[ns_path]];
[quartz->priv->ns_query setSearchScopes:@[NSMetadataQueryLocalComputerScope]];
[quartz->priv->ns_query setSearchItems:@[(NSString*)kMDItemTextContent,
[quartz->priv->ns_query setPredicate:
[NSPredicate predicateWithFormat:
[NSString stringWithFormat:@"(kMDItemTextContent LIKE[cd] \"*%s*\")",
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment