2012-11-02 285 views
2

我试图创建一个使用NSMetaDataQuery搜索查询和如下部署谓词:搜索字符串谓词

NSString * format = @"kMDItemDisplayName like[cd] %@"; 
NSPredicate * compPred = [NSPredicate predicateWithFormat:format,[NSString stringWithFormat:@"%@*",self.searchString]]; 

我面临的问题是:

假设我的名字有应用:谷歌浏览器。

如果我搜索“谷歌”作为搜索字符串,我可以得到结果,即“谷歌浏览器”,但如果我搜索“铬”,我无法搜索“谷歌浏览器”。

同样,如果搜索字符串是“Suhail”,显示结果为“Suhail恨任何人”, 但如果搜索字符串是“恨”,结果dosent显示任何东西。

再一种情况: 假设文件名是“faMee”。

我搜索“amee”,结果不算什么。 我搜索“mee”,结果不算什么,但在聚光灯下我搜索“mee”,它显示我文件“faMee”。

请提出任何建议。

回答

0

嗯,而不是在你的查询“喜欢”,使用“包含”。 请通过NSPredicate Apple文档和查询示例。

穆赫辛

+0

未知类型NSComparisonPredicate的(kMDItemDisplayName包含:[CD] “S”),这是我所得到的,如果我使用含有而非像:( – Suhaiyl

0
NSPredicate * compPred = [NSPredicate predicateWithFormat:format,[NSString stringWithFormat:@"*%@*",self.searchString]]; 

尝试给NSMetadataQuery这