2

I am trying to create a search query using NSMetaDataQuery and deploying a predicate as below :

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

The issue i am facing is :

Suppose i have application by name : Google Chrome.

If i search for "google" as search string, i am able to get the result i.e "Google Chrome", but if i am searching for "chrome", i am not able to search "Google Chrome".

Similarly if search string is "Suhail", display result is "Suhail hates no one ", but if search string is "hates", result dosent show anything.

One more case: suppose file name is "faMee".

I search for "amee", result is nothing. I search for "mee", result is nothing, but in spotlight is i search for "mee" it displays me the file "faMee".

Any suggestions please.

Suhaiyl
  • 1,071
  • 9
  • 17

2 Answers2

0

Well rather than "like" in your query, use "contains". Please go through with the NSPredicate Apple documentation and sample on the queries.

Mohsin

  • Unknown type of NSComparisonPredicate given to NSMetadataQuery (kMDItemDisplayName CONTAINS[cd] "s"), this is what i get if i use contains instead of like :( – Suhaiyl Nov 02 '12 at 12:44
0
NSPredicate * compPred = [NSPredicate predicateWithFormat:format,[NSString stringWithFormat:@"*%@*",self.searchString]];

Try This

Akhil Shrivastav
  • 427
  • 3
  • 13