objective-c - 针对 kMDItemPath 的搜索在 Spotlight 中没有结果

标签 objective-c cocoa osx-leopard spotlight

我正在尝试创建一个 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.

Link

这意味着属性 kMDItemPath 只能与 MDItem 或 NSMetadataItem 一起使用来检索已找到的项目的路径。您不能在指定的查询谓词中将其与 MDQuery 或 NSMetadataQuery 一起使用以查找文件。

关于objective-c - 针对 kMDItemPath 的搜索在 Spotlight 中没有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1341590/

相关文章:

cocoa - 如何在 xCode 4 中添加 10.5 的基础 SDK

ios - 在 iOS 中绘制一个手势控制可调整大小的圆圈

ios - 无法获取核心数据持久存储的元数据

cocoa - 如何改变 cocoa 中窗口标题栏的高度?

objective-c - 使用 NSFileHandle 创建 UTF8 文本文件时出现问题

xcode - 在 Xcode 3.2 中构建 10.5(在雪豹上)错误

python - 如何从 OSX Leopard 卸载 python 以便可以使用 MacPorts 版本?

objective-c - 计时器因调整窗口大小而延迟

ios - SDWebImageCache 预缓存图像

xcode - 从 NSArray 中删除不需要的数据