开发者

NSMetaDataQuery, set the setSearchScope paths to be recursive?

In Objective-C, I am setting up an NSMetaDataQuery and setting the setSearchScope: for the query to s开发者_JAVA技巧earch a specific users Documents folder. The search works but doesn't recurse down the directory tree, only searching in the Documents folder.

I've tried wildcards but no joy.

Here is basically what I've attempted, and it works except not searching below the Documents directory:

query = [[NSMetadataQuery alloc] init];
[query setSearchScopes:[NSArray arrayWithObjects:@"/Users/username/Documents/",nil]];
[query setPredicate:[NSPredicate predicateWithFormat:@"(kMDItemFSContentChangeDate >= '$time.this_week')"]];
[query startQuery];


I think that the problem is with your NSPredicate format string. (I have been meaning to write this up!) Essentially, your $time.this_week would work great in a Spotlight query, but not as a NSPredicate string. You have to actually create an NSDate object and pass it into the query string like

[query setPredicate:[NSPredicate predicateWithFormat:@"(kMDItemFSContentChangeDate <= %@)", [NSDate date]]];

Here are the relevant links for your reference:

Comparison of NSPredicate and Spotlight Query Strings
Spotlight Query Expression Syntax
Predicate Format String Syntax


I think your problem might be the trailing slash on /Users/username/Documents/. When dealing with paths in Objective-C, the framework never puts on a trailing slash. Does taking it off help?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜