NSMetadataQuery数据库
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NSMetadataQuery数据库相关的知识,希望对你有一定的参考价值。
(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
以上是关于NSMetadataQuery数据库的主要内容,如果未能解决你的问题,请参考以下文章
禁用 iCloud 时是不是可以使用 NSMetadataQuery?
UIDocument openWithCompletionHandler:强制 NSMetadataQuery 更新
如何限制从 NSMetadataQuery 返回的结果数量?