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: Corbin Dunn <email@hidden>
- Date: Tue, 5 Jul 2005 09:42:12 -0700
Here are a few comments:
[query setSearchScopes: [NSArray arrayWithObjects: @"/System/
Library/", nil]];
// this works
[query setPredicate: [NSPredicate predicateWithFormat:
@"(kMDItemDisplayName like[cd] '*.strings') && (kMDItemDisplayName !
= 'InfoPlist.strings') && (kMDItemContent !=
'com.apple.mail.emix') && (kMDItemContent != 'public.vcard')"]];
Yes; it finds all the .strings files and the format is correct.
/* none of these do
[query setPredicate: [NSPredicate predicateWithFormat:
@"(kMDItemKind = '*Strings File*'cd) && (kMDItemDisplayName !=
'InfoPlist.strings') && (kMDItemContent != 'com.apple.mail.emix')
&& (kMDItemContent != 'public.vcard')"]];
This is not parsable; you are mixing spotlight syntax with
NSPredicate syntax. The "cd" shouldn't be there, and you should use
LIKE[cd] instead (it translates into a spotlight query string of
basically what you typed).
[query setPredicate: [NSPredicate predicateWithFormat:
@"(kMDItemKind = 'Strings File'cd) && (kMDItemDisplayName !=
'InfoPlist.strings') && (kMDItemContent != 'com.apple.mail.emix')
&& (kMDItemContent != 'public.vcard')"]];
Same problem as above; you actually get an error on the console when
you have bad query formats like these.
[query setPredicate: [NSPredicate predicateWithFormat:
@"(kMDItemKind like[cd] '*Strings File*') && (kMDItemDisplayName !=
'InfoPlist.strings') && (kMDItemContent != 'com.apple.mail.emix')
&& (kMDItemContent != 'public.vcard')"]];
This is a valid NSPredicate. However, in the scope you specified, /
System/Library, there are files that have a displayname of *.strings,
but none of them have a kMDItemKind atribute of "Strings File" (try
to verify it by doing an "mdls" on some of the .strings files in that
directory -- none have that attribute). This is why it comes up with
0 results in this case, but a bunch of results in the first case.
[query setPredicate: [NSPredicate predicateWithFormat:
@"(kMDItemKind like[cd] 'Strings File'cd) && (kMDItemDisplayName !=
'InfoPlist.strings') && (kMDItemContent != 'com.apple.mail.emix')
&& (kMDItemContent != 'public.vcard')"]];
Again, another bad format.
--corbin
_______________________________________________
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