No results in Spotlight in searches against kMDItemPath
Asked Answered
S

1

5

I am trying to create a Spotlight query that searches for a string in the path of a file (I would like it to match in either the name of the file or the name of any of the folders is contained in).

NSPredicate *predicateTemplate = [NSPredicate predicateWithFormat: @"kMDItemPath like[wcd] $SEARCH";
[query setPredicate: 
    [predicateTemplate predicateWithSubstitutionVariables:
        [NSDictionary dictionaryWithObject:searchingFor forKey:@"SEARCH"]
    ]
];
[query startQuery];

This always returns 0 results, even if the following one:

NSPredicate *predicateTemplate = [NSPredicate predicateWithFormat: @"kMDItemDisplayName in[wcd] $SEARCH";

returns 1 or more results. I am testing this on MacOS X 10.5.8.

Sweatband answered 27/8, 2009 at 14:46 Comment(0)
C
11

Quoth the documentation:

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

That means that the attribute kMDItemPath can only be used with a MDItem or NSMetadataItem to retrieve the path for an item already found. You cannot use it with an MDQuery or an NSMetadataQuery within the query predicate you specify to find files.

Chapbook answered 27/8, 2009 at 15:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.