【问题标题】:NSMetaDataQuery, set the setSearchScope paths to be recursive?NSMetaDataQuery,将 setSearchScope 路径设置为递归?
【发布时间】:2011-05-08 01:08:58
【问题描述】:

在 Objective-C 中,我为查询设置了 NSMetaDataQuery 并设置了 setSearchScope: 以搜索特定用户的 Documents 文件夹。搜索有效,但不会沿目录树递归,仅在 Documents 文件夹中搜索。
我试过通配符,但没有乐趣。

这基本上是我尝试过的,除了不在 Documents 目录下搜索之外,它可以工作:

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

【问题讨论】:

    标签: objective-c cocoa spotlight nsmetadataquery


    【解决方案1】:

    我认为问题出在您的 NSPredicate 格式字符串上。 (我一直想写这个!)本质上,您的$time.this_week 在 Spotlight 查询中会很好用,但不能作为 NSPredicate 字符串。您必须实际创建一个 NSDate 对象并将其传递给查询字符串,如

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

    以下是相关链接供您参考:

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

    【讨论】:

      【解决方案2】:

      我认为您的问题可能是/Users/username/Documents/ 上的斜杠。在 Objective-C 中处理路径时,框架从不使用尾部斜杠。取下来有用吗?

      【讨论】:

      猜你喜欢
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 2013-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多