我正在尝试创建一个 Spotlight 查询来搜索文件路径中的字符串(我希望它匹配文件名或其中包含的任何文件夹的名称)。
NSPredicate *predicateTemplate = [NSPredicate predicateWithFormat: @"kMDItemPath like[wcd] $SEARCH";
[query setPredicate:
[predicateTemplate predicateWithSubstitutionVariables:
[NSDictionary dictionaryWithObject:searchingFor forKey:@"SEARCH"]
]
];
[query startQuery];
这总是返回 0 个结果,即使是以下结果:
NSPredicate *predicateTemplate = [NSPredicate predicateWithFormat: @"kMDItemDisplayName in[wcd] $SEARCH";
返回 1 个或多个结果。我正在 MacOS X 10.5.8 上对此进行测试。
最佳答案
引用文档:
kMDItemPath
Complete path to the file. This value of this attribute can be retrieved, but can't be used in a query or to sort search results.
这意味着属性 kMDItemPath
只能与 MDItem 或 NSMetadataItem 一起使用来检索已找到的项目的路径。您不能在指定的查询谓词中将其与 MDQuery 或 NSMetadataQuery 一起使用以查找文件。
关于objective-c - 针对 kMDItemPath 的搜索在 Spotlight 中没有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1341590/