[gtk/gtk-3-24] [GtkSearchEngineQuartz] Limit the scope of the Spotlight search.
- From: John Ralls <jralls src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/gtk-3-24] [GtkSearchEngineQuartz] Limit the scope of the Spotlight search.
- Date: Tue, 12 Mar 2019 01:03:41 +0000 (UTC)
commit 75b8abbf24379f2a4bda274d550131b8de48aee3
Author: John Ralls <jralls ceridwen us>
Date: Fri Jan 11 16:14:28 2019 -0800
[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.
gtk/gtksearchenginequartz.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
---
diff --git a/gtk/gtksearchenginequartz.c b/gtk/gtksearchenginequartz.c
index f408c415a8..c260b51025 100644
--- a/gtk/gtksearchenginequartz.c
+++ b/gtk/gtksearchenginequartz.c
@@ -192,6 +192,8 @@ gtk_search_engine_quartz_set_query (GtkSearchEngine *engine,
GtkQuery *query)
{
GtkSearchEngineQuartz *quartz;
+ const char* path = NULL;
+ GFile *location = NULL;
QUARTZ_POOL_ALLOC;
@@ -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]];
+ }
+ else
+ {
+ [quartz->priv->ns_query setSearchScopes:@[NSMetadataQueryLocalComputerScope]];
+ }
+
+ [quartz->priv->ns_query setSearchItems:@[(NSString*)kMDItemTextContent,
+ (NSString*)kMDItemFSName]];
[quartz->priv->ns_query setPredicate:
[NSPredicate predicateWithFormat:
[NSString stringWithFormat:@"(kMDItemTextContent LIKE[cd] \"*%s*\")",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]