/ Published in: Objective C
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
(null)/(null)/(null) (null) | Permalink NSMetadataQuery seems to have bugs and unable to get NSMetadataQueryResultContentRelevanceAttribute value. Use MDQueryRef instead. #import { IBOutlet id field; MDQueryRef _query; } - (IBAction)search:(id)sender; @end --------- #import "MyDocument.h" @implementation MyDocument - (id)init { self = [super init]; if (self) { } return self; } { return @"MyDocument"; } { [super windowControllerDidLoadNib:aController]; } - (IBAction)search:(id)sender { if( [[field stringValue] isEqualToString:@"" ] ) return; NSString *predicateFormat = @"(kMDItemTextContent == \"?%@*\"c) && (kMDItemContentType != 'com.apple.mail.emlx') && (kMDItemContentType != 'public.vcard')"; _query = MDQueryCreate ( NULL, kMDItemPath, kMDItemDisplayName, kMDItemFSName,nil ], ); MDQuerySetSearchScope ( _query, 0 ); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(finish) name:kMDQueryDidFinishNotification object:_query]; MDQueryExecute ( _query, kMDQuerySynchronous ); } -(void)finish { name:nil object:_query]; MDItemRef miref; CFIndex idx; idx = MDQueryGetResultCount(_query); CFIndex hoge; for( hoge = 0; hoge < idx; hoge++ ) { miref = MDQueryGetResultAtIndex( _query, hoge); miref, kMDItemFSName ); miref, kMDItemPath ); miref, kMDItemDisplayName ); _query, kMDQueryResultContentRelevance, hoge ); if( score != nil ) NSLog(@"score %f",[score floatValue]); } } @end
URL: http://homepage.mac.com/mnishikata/page2/page2.html