Re: NSMetadataQuery not handling scopes and predicates as expected
Re: NSMetadataQuery not handling scopes and predicates as expected
- Subject: Re: NSMetadataQuery not handling scopes and predicates as expected
- From: Ken Tozier <email@hidden>
- Date: Sun, 3 Jul 2005 07:27:14 -0400
On Jul 3, 2005, at 6:14 AM, Scott Anguish wrote:
On Jul 3, 2005, at 2:40 AM, Ken Tozier wrote:
I managed to get some NSMetadataQuerys working but when attempting
to use any of the scope constants, the query returns immediately
with no results. Here's the various syntaxes I've tried:
NSMetadataQuery *query = [[NSMetadataQuery alloc] init];
This works
[query setSearchScopes: [NSArray arrayWithObjects: @"/System/
Library/", nil]];
which is interesting, as I don't believe anything in /System is
actually indexed. You'll be able to search on File metadata items,
but nothing else...
I'm just using it as a quick way to get a list of paths to specific
types of ".strings" files. I loop through the result list, read the
content and process them myself.
again.. interesting.. I think this must be a problem with your
app, because if you run the Spotlighter example, and enter *String
File* you get loads of .strings files showing up
I'm thinking that the string parser in NSPredicate's
predicateWithFormat method might not be 100% yet.
Here's the relevant Spotlight code. See any glaring errors?
@interface MetadataTest : NSObject
{
NSMetadataQuery *query;
}
- (void) queryHandler:(NSNotification *) inNotification;
@end
@implementation MetadataTest
- (id) init
{
self = [super init];
if (self == nil)
return nil;
query = [[NSMetadataQuery alloc] init];
// this works
[query setSearchScopes: [NSArray arrayWithObjects: @"/System/
Library/", nil]];
/* none of these do
[query setSearchScopes: [NSArray arrayWithObjects:
NSMetadataQueryUserHomeScope", nil]];
[query setSearchScopes: [NSArray arrayWithObjects:
NSMetadataQueryLocalComputerScope, nil]];
*/
// this works
[query setPredicate: [NSPredicate predicateWithFormat:
@"(kMDItemDisplayName like[cd] '*.strings') && (kMDItemDisplayName !=
'InfoPlist.strings') && (kMDItemContent !=
'com.apple.mail.emix') && (kMDItemContent != 'public.vcard')"]];
/* none of these do
[query setPredicate: [NSPredicate predicateWithFormat:
@"(kMDItemKind = '*Strings File*'cd) && (kMDItemDisplayName !=
'InfoPlist.strings') && (kMDItemContent != 'com.apple.mail.emix') &&
(kMDItemContent != 'public.vcard')"]];
[query setPredicate: [NSPredicate predicateWithFormat:
@"(kMDItemKind = 'Strings File'cd) && (kMDItemDisplayName !=
'InfoPlist.strings') && (kMDItemContent != 'com.apple.mail.emix') &&
(kMDItemContent != 'public.vcard')"]];
[query setPredicate: [NSPredicate predicateWithFormat:
@"(kMDItemKind like[cd] '*Strings File*') && (kMDItemDisplayName !=
'InfoPlist.strings') && (kMDItemContent != 'com.apple.mail.emix') &&
(kMDItemContent != 'public.vcard')"]];
[query setPredicate: [NSPredicate predicateWithFormat:
@"(kMDItemKind like[cd] 'Strings File'cd) && (kMDItemDisplayName !=
'InfoPlist.strings') && (kMDItemContent != 'com.apple.mail.emix') &&
(kMDItemContent != 'public.vcard')"]];
*/
// Set up query doneTo watch results send by the query, add an
observer to the NSNotificationCenter
[[NSNotificationCenter defaultCenter]
addObserver: self
selector:@selector(queryHandler:)
name: NSMetadataQueryDidFinishGatheringNotification
object: query];
[query startQuery];
return self;
}
- (void) queryHandler:(NSNotification *) inNotification
{
NSLog(@"query result count = %@", [NSNumber numberWithInt:
[query resultCount]]);
/* handle the results here */
}
@end
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden